state
stringlengths
0
159k
srcUpToTactic
stringlengths
387
167k
nextTactic
stringlengths
3
9k
declUpToTactic
stringlengths
22
11.5k
declId
stringlengths
38
95
decl
stringlengths
16
1.89k
file_tag
stringlengths
17
73
case h.e'_4 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f g : ΞΉ β†’ R s t : Finset ΞΉ h0 : βˆ€ i ∈ s, 0 ≀ f i h1 : βˆ€ i ∈ s, f i ≀ 1 ⊒ ∏ i in s, 1 = 1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1
exact Finset.prod_const_one
/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1
Mathlib.Algebra.BigOperators.Order.629_0.ewL52iF1Dz3xeLh
/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ ∏ i in s, g i + ∏ i in s, h i ≀ ∏ i in s, f i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by
simp_rw [prod_eq_mul_prod_diff_singleton hi]
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ g i * ∏ i in s \ {i}, g i + h i * ∏ i in s \ {i}, h i ≀ f i * ∏ i in s \ {i}, f i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi]
refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi]
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ 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
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β·
rw [right_distrib]
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β·
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ 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
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib]
refine add_le_add ?_ ?_
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib]
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1.refine_1 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ g i * ∏ i in s \ {i}, g i ≀ g i * ∏ i in s \ {i}, f i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β·
refine mul_le_mul_of_nonneg_left ?_ ?_
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β·
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1.refine_1.refine_1 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ ∏ i in s \ {i}, g i ≀ ∏ i in s \ {i}, f i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β·
refine prod_le_prod ?_ ?_
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β·
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1.refine_1.refine_1.refine_1 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ βˆ€ i_1 ∈ s \ {i}, 0 ≀ g i_1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;>
simp (config := { contextual := true }) [*]
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;>
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1.refine_1.refine_1.refine_2 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ βˆ€ i_1 ∈ s \ {i}, g i_1 ≀ f i_1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;>
simp (config := { contextual := true }) [*]
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;>
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1.refine_1.refine_2 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ 0 ≀ g i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β·
try apply_assumption
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β·
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1.refine_1.refine_2 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ 0 ≀ g i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try
apply_assumption
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1.refine_1.refine_2.a ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ i ∈ s
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption
try assumption
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1.refine_1.refine_2.a ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ i ∈ s
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try
assumption
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1.refine_2 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ h i * ∏ i in s \ {i}, h i ≀ h i * ∏ i in s \ {i}, f i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β·
refine mul_le_mul_of_nonneg_left ?_ ?_
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β·
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1.refine_2.refine_1 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ ∏ i in s \ {i}, h i ≀ ∏ i in s \ {i}, f i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β·
refine prod_le_prod ?_ ?_
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β·
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1.refine_2.refine_1.refine_1 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ βˆ€ i_1 ∈ s \ {i}, 0 ≀ h i_1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;>
simp (config := { contextual := true }) [*]
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;>
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1.refine_2.refine_1.refine_2 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ βˆ€ i_1 ∈ s \ {i}, h i_1 ≀ f i_1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;>
simp (config := { contextual := true }) [*]
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;>
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1.refine_2.refine_2 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ 0 ≀ h i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β·
try apply_assumption
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β·
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1.refine_2.refine_2 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ 0 ≀ h i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try
apply_assumption
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1.refine_2.refine_2.a ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ i ∈ s
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption
try assumption
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_1.refine_2.refine_2.a ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ i ∈ s
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try
assumption
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_2 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ 0 ≀ ∏ i in s \ {i}, f i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β·
apply prod_nonneg
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β·
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_2.h0 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ βˆ€ i_1 ∈ s \ {i}, 0 ≀ f i_1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg
simp only [and_imp, mem_sdiff, mem_singleton]
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_2.h0 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i ⊒ βˆ€ i_1 ∈ s, Β¬i_1 = i β†’ 0 ≀ f i_1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton]
intro j h1j h2j
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton]
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case refine_2.h0 ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : OrderedCommSemiring R f✝ g✝ : ΞΉ β†’ R s t : Finset ΞΉ i : ΞΉ f g h : ΞΉ β†’ R hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j hg : βˆ€ i ∈ s, 0 ≀ g i hh : βˆ€ i ∈ s, 0 ≀ h i j : ΞΉ h1j : j ∈ s h2j : Β¬j = i ⊒ 0 ≀ f j
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j
exact le_trans (hg j h1j) (hgf j h1j h2j)
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j
Mathlib.Algebra.BigOperators.Order.636_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : StrictOrderedCommSemiring R f g : ΞΉ β†’ R s : Finset ΞΉ hf : βˆ€ i ∈ s, 0 < f i hfg : βˆ€ i ∈ s, f i ≀ g i hlt : βˆƒ i ∈ s, f i < g i ⊒ ∏ i in s, f i < ∏ i in s, g i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by
classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt
theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by
Mathlib.Algebra.BigOperators.Order.667_0.ewL52iF1Dz3xeLh
theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : StrictOrderedCommSemiring R f g : ΞΉ β†’ R s : Finset ΞΉ hf : βˆ€ i ∈ s, 0 < f i hfg : βˆ€ i ∈ s, f i ≀ g i hlt : βˆƒ i ∈ s, f i < g i ⊒ ∏ i in s, f i < ∏ i in s, g i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical
obtain ⟨i, hi, hilt⟩ := hlt
theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical
Mathlib.Algebra.BigOperators.Order.667_0.ewL52iF1Dz3xeLh
theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i
Mathlib_Algebra_BigOperators_Order
case intro.intro ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : StrictOrderedCommSemiring R f g : ΞΉ β†’ R s : Finset ΞΉ hf : βˆ€ i ∈ s, 0 < f i hfg : βˆ€ i ∈ s, f i ≀ g i i : ΞΉ hi : i ∈ s hilt : f i < g i ⊒ ∏ i in s, f i < ∏ i in s, g i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt
rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)]
theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt
Mathlib.Algebra.BigOperators.Order.667_0.ewL52iF1Dz3xeLh
theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i
Mathlib_Algebra_BigOperators_Order
case intro.intro ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : StrictOrderedCommSemiring R f g : ΞΉ β†’ R s : Finset ΞΉ hf : βˆ€ i ∈ s, 0 < f i hfg : βˆ€ i ∈ s, f i ≀ g i i : ΞΉ hi : i ∈ s hilt : f i < g i ⊒ f i * ∏ x in erase s i, f x < g i * ∏ x in erase s i, g x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)]
apply mul_lt_mul hilt
theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)]
Mathlib.Algebra.BigOperators.Order.667_0.ewL52iF1Dz3xeLh
theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i
Mathlib_Algebra_BigOperators_Order
case intro.intro.hbd ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : StrictOrderedCommSemiring R f g : ΞΉ β†’ R s : Finset ΞΉ hf : βˆ€ i ∈ s, 0 < f i hfg : βˆ€ i ∈ s, f i ≀ g i i : ΞΉ hi : i ∈ s hilt : f i < g i ⊒ ∏ x in erase s i, f x ≀ ∏ x in erase s i, g x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β·
exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)
theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β·
Mathlib.Algebra.BigOperators.Order.667_0.ewL52iF1Dz3xeLh
theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i
Mathlib_Algebra_BigOperators_Order
case intro.intro.hb ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : StrictOrderedCommSemiring R f g : ΞΉ β†’ R s : Finset ΞΉ hf : βˆ€ i ∈ s, 0 < f i hfg : βˆ€ i ∈ s, f i ≀ g i i : ΞΉ hi : i ∈ s hilt : f i < g i ⊒ 0 < ∏ x in erase s i, f x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β·
exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)
theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β·
Mathlib.Algebra.BigOperators.Order.667_0.ewL52iF1Dz3xeLh
theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i
Mathlib_Algebra_BigOperators_Order
case intro.intro.hc ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : StrictOrderedCommSemiring R f g : ΞΉ β†’ R s : Finset ΞΉ hf : βˆ€ i ∈ s, 0 < f i hfg : βˆ€ i ∈ s, f i ≀ g i i : ΞΉ hi : i ∈ s hilt : f i < g i ⊒ 0 ≀ g i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β·
exact le_of_lt <| (hf i hi).trans hilt
theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β·
Mathlib.Algebra.BigOperators.Order.667_0.ewL52iF1Dz3xeLh
theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : StrictOrderedCommSemiring R f g : ΞΉ β†’ R s : Finset ΞΉ hf : βˆ€ i ∈ s, 0 < f i hfg : βˆ€ i ∈ s, f i < g i h_ne : Finset.Nonempty s ⊒ ∏ i in s, f i < ∏ i in s, g i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by
apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)
theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by
Mathlib.Algebra.BigOperators.Order.679_0.ewL52iF1Dz3xeLh
theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : StrictOrderedCommSemiring R f g : ΞΉ β†’ R s : Finset ΞΉ hf : βˆ€ i ∈ s, 0 < f i hfg : βˆ€ i ∈ s, f i < g i h_ne : Finset.Nonempty s ⊒ βˆƒ i ∈ s, f i < g i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)
obtain ⟨i, hi⟩ := h_ne
theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)
Mathlib.Algebra.BigOperators.Order.679_0.ewL52iF1Dz3xeLh
theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i
Mathlib_Algebra_BigOperators_Order
case intro ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : StrictOrderedCommSemiring R f g : ΞΉ β†’ R s : Finset ΞΉ hf : βˆ€ i ∈ s, 0 < f i hfg : βˆ€ i ∈ s, f i < g i i : ΞΉ hi : i ∈ s ⊒ βˆƒ i ∈ s, f i < g i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne
exact ⟨i, hi, hfg i hi⟩
theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne
Mathlib.Algebra.BigOperators.Order.679_0.ewL52iF1Dz3xeLh
theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j ⊒ ∏ i in s, g i + ∏ i in s, h i ≀ ∏ i in s, f i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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
classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;> assumption
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j ⊒ ∏ i in s, g i + ∏ i in s, h i ≀ ∏ i in s, f i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical
simp_rw [prod_eq_mul_prod_diff_singleton hi]
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j ⊒ g i * ∏ i in s \ {i}, g i + h i * ∏ i in s \ {i}, h i ≀ f i * ∏ i in s \ {i}, f i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi]
refine' le_trans _ (mul_le_mul_right' h2i _)
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi]
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j ⊒ 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
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _)
rw [right_distrib]
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _)
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j ⊒ 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
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib]
apply add_le_add
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib]
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case h₁ ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j ⊒ g i * ∏ i in s \ {i}, g i ≀ g i * ∏ i in s \ {i}, f i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;>
apply mul_le_mul_left'
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;>
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case hβ‚‚ ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j ⊒ h i * ∏ i in s \ {i}, h i ≀ h i * ∏ i in s \ {i}, f i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;>
apply mul_le_mul_left'
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;>
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case h₁.bc ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j ⊒ ∏ i in s \ {i}, g i ≀ ∏ i in s \ {i}, f i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;>
apply prod_le_prod'
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;>
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case hβ‚‚.bc ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j ⊒ ∏ i in s \ {i}, h i ≀ ∏ i in s \ {i}, f i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;>
apply prod_le_prod'
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;>
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case h₁.bc.h ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j ⊒ βˆ€ i_1 ∈ s \ {i}, g i_1 ≀ f i_1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>
simp only [and_imp, mem_sdiff, mem_singleton]
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case hβ‚‚.bc.h ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j ⊒ βˆ€ i_1 ∈ s \ {i}, h i_1 ≀ f i_1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>
simp only [and_imp, mem_sdiff, mem_singleton]
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case h₁.bc.h ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j ⊒ βˆ€ i_1 ∈ s, Β¬i_1 = i β†’ g i_1 ≀ f i_1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;>
intros
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;>
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case hβ‚‚.bc.h ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j ⊒ βˆ€ i_1 ∈ s, Β¬i_1 = i β†’ h i_1 ≀ f i_1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;>
intros
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;>
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case h₁.bc.h ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j i✝ : ΞΉ a✝¹ : i✝ ∈ s a✝ : Β¬i✝ = i ⊒ g i✝ ≀ f i✝
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;>
apply_assumption
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;>
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case hβ‚‚.bc.h ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j i✝ : ΞΉ a✝¹ : i✝ ∈ s a✝ : Β¬i✝ = i ⊒ h i✝ ≀ f i✝
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;>
apply_assumption
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;>
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case h₁.bc.h.a ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j i✝ : ΞΉ a✝¹ : i✝ ∈ s a✝ : Β¬i✝ = i ⊒ i✝ ∈ s
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;>
assumption
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;>
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case h₁.bc.h.a ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j i✝ : ΞΉ a✝¹ : i✝ ∈ s a✝ : Β¬i✝ = i ⊒ i✝ β‰  i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;>
assumption
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;>
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case hβ‚‚.bc.h.a ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j i✝ : ΞΉ a✝¹ : i✝ ∈ s a✝ : Β¬i✝ = i ⊒ i✝ ∈ s
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;>
assumption
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;>
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
case hβ‚‚.bc.h.a ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : CanonicallyOrderedCommSemiring R f g h : ΞΉ β†’ R s : Finset ΞΉ i : ΞΉ hi : i ∈ s h2i : g i + h i ≀ f i hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j i✝ : ΞΉ a✝¹ : i✝ ∈ s a✝ : Β¬i✝ = i ⊒ i✝ β‰  i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;>
assumption
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;>
Mathlib.Algebra.BigOperators.Order.698_0.ewL52iF1Dz3xeLh
/-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝¹ : Fintype ΞΉ inst✝ : OrderedCancelCommMonoid M f : ΞΉ β†’ M hf : 1 < f ⊒ βˆƒ i ∈ Finset.univ, 1 < f i
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;> assumption #align finset.prod_add_prod_le' Finset.prod_add_prod_le' end CanonicallyOrderedCommSemiring end Finset namespace Fintype section OrderedCommMonoid variable [Fintype ΞΉ] [OrderedCommMonoid M] {f : ΞΉ β†’ M} @[to_additive (attr := mono) sum_mono] theorem prod_mono' : Monotone fun f : ΞΉ β†’ M ↦ ∏ i, f i := fun _ _ hfg ↦ Finset.prod_le_prod' fun x _ ↦ hfg x #align fintype.prod_mono' Fintype.prod_mono' #align fintype.sum_mono Fintype.sum_mono @[to_additive sum_nonneg] lemma one_le_prod (hf : 1 ≀ f) : 1 ≀ ∏ i, f i := Finset.one_le_prod' Ξ» _ _ ↦ hf _ @[to_additive] lemma prod_le_one (hf : f ≀ 1) : ∏ i, f i ≀ 1 := Finset.prod_le_one' Ξ» _ _ ↦ hf _ end OrderedCommMonoid section OrderedCancelCommMonoid variable [Fintype ΞΉ] [OrderedCancelCommMonoid M] {f : ΞΉ β†’ M} @[to_additive sum_strictMono] theorem prod_strictMono' : StrictMono fun f : ΞΉ β†’ M ↦ ∏ x, f x := fun _ _ hfg ↦ let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩ #align fintype.prod_strict_mono' Fintype.prod_strictMono' #align fintype.sum_strict_mono Fintype.sum_strictMono @[to_additive sum_pos] lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i := Finset.one_lt_prod' (Ξ» _ _ ↦ hf.le _) $ by
simpa using (Pi.lt_def.1 hf).2
@[to_additive sum_pos] lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i := Finset.one_lt_prod' (Ξ» _ _ ↦ hf.le _) $ by
Mathlib.Algebra.BigOperators.Order.746_0.ewL52iF1Dz3xeLh
@[to_additive sum_pos] lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝¹ : Fintype ΞΉ inst✝ : OrderedCancelCommMonoid M f : ΞΉ β†’ M hf : f < 1 ⊒ βˆƒ i ∈ Finset.univ, f i < 1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;> assumption #align finset.prod_add_prod_le' Finset.prod_add_prod_le' end CanonicallyOrderedCommSemiring end Finset namespace Fintype section OrderedCommMonoid variable [Fintype ΞΉ] [OrderedCommMonoid M] {f : ΞΉ β†’ M} @[to_additive (attr := mono) sum_mono] theorem prod_mono' : Monotone fun f : ΞΉ β†’ M ↦ ∏ i, f i := fun _ _ hfg ↦ Finset.prod_le_prod' fun x _ ↦ hfg x #align fintype.prod_mono' Fintype.prod_mono' #align fintype.sum_mono Fintype.sum_mono @[to_additive sum_nonneg] lemma one_le_prod (hf : 1 ≀ f) : 1 ≀ ∏ i, f i := Finset.one_le_prod' Ξ» _ _ ↦ hf _ @[to_additive] lemma prod_le_one (hf : f ≀ 1) : ∏ i, f i ≀ 1 := Finset.prod_le_one' Ξ» _ _ ↦ hf _ end OrderedCommMonoid section OrderedCancelCommMonoid variable [Fintype ΞΉ] [OrderedCancelCommMonoid M] {f : ΞΉ β†’ M} @[to_additive sum_strictMono] theorem prod_strictMono' : StrictMono fun f : ΞΉ β†’ M ↦ ∏ x, f x := fun _ _ hfg ↦ let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩ #align fintype.prod_strict_mono' Fintype.prod_strictMono' #align fintype.sum_strict_mono Fintype.sum_strictMono @[to_additive sum_pos] lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i := Finset.one_lt_prod' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive] lemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 := Finset.prod_lt_one' (Ξ» _ _ ↦ hf.le _) $ by
simpa using (Pi.lt_def.1 hf).2
@[to_additive] lemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 := Finset.prod_lt_one' (Ξ» _ _ ↦ hf.le _) $ by
Mathlib.Algebra.BigOperators.Order.750_0.ewL52iF1Dz3xeLh
@[to_additive] lemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝¹ : Fintype ΞΉ inst✝ : OrderedCancelCommMonoid M f : ΞΉ β†’ M hf : 1 ≀ f ⊒ 1 < ∏ i : ΞΉ, f i ↔ 1 < f
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;> assumption #align finset.prod_add_prod_le' Finset.prod_add_prod_le' end CanonicallyOrderedCommSemiring end Finset namespace Fintype section OrderedCommMonoid variable [Fintype ΞΉ] [OrderedCommMonoid M] {f : ΞΉ β†’ M} @[to_additive (attr := mono) sum_mono] theorem prod_mono' : Monotone fun f : ΞΉ β†’ M ↦ ∏ i, f i := fun _ _ hfg ↦ Finset.prod_le_prod' fun x _ ↦ hfg x #align fintype.prod_mono' Fintype.prod_mono' #align fintype.sum_mono Fintype.sum_mono @[to_additive sum_nonneg] lemma one_le_prod (hf : 1 ≀ f) : 1 ≀ ∏ i, f i := Finset.one_le_prod' Ξ» _ _ ↦ hf _ @[to_additive] lemma prod_le_one (hf : f ≀ 1) : ∏ i, f i ≀ 1 := Finset.prod_le_one' Ξ» _ _ ↦ hf _ end OrderedCommMonoid section OrderedCancelCommMonoid variable [Fintype ΞΉ] [OrderedCancelCommMonoid M] {f : ΞΉ β†’ M} @[to_additive sum_strictMono] theorem prod_strictMono' : StrictMono fun f : ΞΉ β†’ M ↦ ∏ x, f x := fun _ _ hfg ↦ let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩ #align fintype.prod_strict_mono' Fintype.prod_strictMono' #align fintype.sum_strict_mono Fintype.sum_strictMono @[to_additive sum_pos] lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i := Finset.one_lt_prod' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive] lemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 := Finset.prod_lt_one' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f := by
obtain rfl | hf := hf.eq_or_lt
@[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f := by
Mathlib.Algebra.BigOperators.Order.754_0.ewL52iF1Dz3xeLh
@[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f
Mathlib_Algebra_BigOperators_Order
case inl ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝¹ : Fintype ΞΉ inst✝ : OrderedCancelCommMonoid M hf : 1 ≀ 1 ⊒ 1 < ∏ i : ΞΉ, OfNat.ofNat 1 i ↔ 1 < 1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;> assumption #align finset.prod_add_prod_le' Finset.prod_add_prod_le' end CanonicallyOrderedCommSemiring end Finset namespace Fintype section OrderedCommMonoid variable [Fintype ΞΉ] [OrderedCommMonoid M] {f : ΞΉ β†’ M} @[to_additive (attr := mono) sum_mono] theorem prod_mono' : Monotone fun f : ΞΉ β†’ M ↦ ∏ i, f i := fun _ _ hfg ↦ Finset.prod_le_prod' fun x _ ↦ hfg x #align fintype.prod_mono' Fintype.prod_mono' #align fintype.sum_mono Fintype.sum_mono @[to_additive sum_nonneg] lemma one_le_prod (hf : 1 ≀ f) : 1 ≀ ∏ i, f i := Finset.one_le_prod' Ξ» _ _ ↦ hf _ @[to_additive] lemma prod_le_one (hf : f ≀ 1) : ∏ i, f i ≀ 1 := Finset.prod_le_one' Ξ» _ _ ↦ hf _ end OrderedCommMonoid section OrderedCancelCommMonoid variable [Fintype ΞΉ] [OrderedCancelCommMonoid M] {f : ΞΉ β†’ M} @[to_additive sum_strictMono] theorem prod_strictMono' : StrictMono fun f : ΞΉ β†’ M ↦ ∏ x, f x := fun _ _ hfg ↦ let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩ #align fintype.prod_strict_mono' Fintype.prod_strictMono' #align fintype.sum_strict_mono Fintype.sum_strictMono @[to_additive sum_pos] lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i := Finset.one_lt_prod' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive] lemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 := Finset.prod_lt_one' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f := by obtain rfl | hf := hf.eq_or_lt <;>
simp [*, one_lt_prod]
@[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f := by obtain rfl | hf := hf.eq_or_lt <;>
Mathlib.Algebra.BigOperators.Order.754_0.ewL52iF1Dz3xeLh
@[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f
Mathlib_Algebra_BigOperators_Order
case inr ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝¹ : Fintype ΞΉ inst✝ : OrderedCancelCommMonoid M f : ΞΉ β†’ M hf✝ : 1 ≀ f hf : 1 < f ⊒ 1 < ∏ i : ΞΉ, f i ↔ 1 < f
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;> assumption #align finset.prod_add_prod_le' Finset.prod_add_prod_le' end CanonicallyOrderedCommSemiring end Finset namespace Fintype section OrderedCommMonoid variable [Fintype ΞΉ] [OrderedCommMonoid M] {f : ΞΉ β†’ M} @[to_additive (attr := mono) sum_mono] theorem prod_mono' : Monotone fun f : ΞΉ β†’ M ↦ ∏ i, f i := fun _ _ hfg ↦ Finset.prod_le_prod' fun x _ ↦ hfg x #align fintype.prod_mono' Fintype.prod_mono' #align fintype.sum_mono Fintype.sum_mono @[to_additive sum_nonneg] lemma one_le_prod (hf : 1 ≀ f) : 1 ≀ ∏ i, f i := Finset.one_le_prod' Ξ» _ _ ↦ hf _ @[to_additive] lemma prod_le_one (hf : f ≀ 1) : ∏ i, f i ≀ 1 := Finset.prod_le_one' Ξ» _ _ ↦ hf _ end OrderedCommMonoid section OrderedCancelCommMonoid variable [Fintype ΞΉ] [OrderedCancelCommMonoid M] {f : ΞΉ β†’ M} @[to_additive sum_strictMono] theorem prod_strictMono' : StrictMono fun f : ΞΉ β†’ M ↦ ∏ x, f x := fun _ _ hfg ↦ let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩ #align fintype.prod_strict_mono' Fintype.prod_strictMono' #align fintype.sum_strict_mono Fintype.sum_strictMono @[to_additive sum_pos] lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i := Finset.one_lt_prod' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive] lemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 := Finset.prod_lt_one' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f := by obtain rfl | hf := hf.eq_or_lt <;>
simp [*, one_lt_prod]
@[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f := by obtain rfl | hf := hf.eq_or_lt <;>
Mathlib.Algebra.BigOperators.Order.754_0.ewL52iF1Dz3xeLh
@[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝¹ : Fintype ΞΉ inst✝ : OrderedCancelCommMonoid M f : ΞΉ β†’ M hf : f ≀ 1 ⊒ ∏ i : ΞΉ, f i < 1 ↔ f < 1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;> assumption #align finset.prod_add_prod_le' Finset.prod_add_prod_le' end CanonicallyOrderedCommSemiring end Finset namespace Fintype section OrderedCommMonoid variable [Fintype ΞΉ] [OrderedCommMonoid M] {f : ΞΉ β†’ M} @[to_additive (attr := mono) sum_mono] theorem prod_mono' : Monotone fun f : ΞΉ β†’ M ↦ ∏ i, f i := fun _ _ hfg ↦ Finset.prod_le_prod' fun x _ ↦ hfg x #align fintype.prod_mono' Fintype.prod_mono' #align fintype.sum_mono Fintype.sum_mono @[to_additive sum_nonneg] lemma one_le_prod (hf : 1 ≀ f) : 1 ≀ ∏ i, f i := Finset.one_le_prod' Ξ» _ _ ↦ hf _ @[to_additive] lemma prod_le_one (hf : f ≀ 1) : ∏ i, f i ≀ 1 := Finset.prod_le_one' Ξ» _ _ ↦ hf _ end OrderedCommMonoid section OrderedCancelCommMonoid variable [Fintype ΞΉ] [OrderedCancelCommMonoid M] {f : ΞΉ β†’ M} @[to_additive sum_strictMono] theorem prod_strictMono' : StrictMono fun f : ΞΉ β†’ M ↦ ∏ x, f x := fun _ _ hfg ↦ let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩ #align fintype.prod_strict_mono' Fintype.prod_strictMono' #align fintype.sum_strict_mono Fintype.sum_strictMono @[to_additive sum_pos] lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i := Finset.one_lt_prod' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive] lemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 := Finset.prod_lt_one' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f := by obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod] @[to_additive] lemma prod_lt_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i < 1 ↔ f < 1 := by
obtain rfl | hf := hf.eq_or_lt
@[to_additive] lemma prod_lt_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i < 1 ↔ f < 1 := by
Mathlib.Algebra.BigOperators.Order.758_0.ewL52iF1Dz3xeLh
@[to_additive] lemma prod_lt_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i < 1 ↔ f < 1
Mathlib_Algebra_BigOperators_Order
case inl ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝¹ : Fintype ΞΉ inst✝ : OrderedCancelCommMonoid M hf : 1 ≀ 1 ⊒ ∏ i : ΞΉ, OfNat.ofNat 1 i < 1 ↔ 1 < 1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;> assumption #align finset.prod_add_prod_le' Finset.prod_add_prod_le' end CanonicallyOrderedCommSemiring end Finset namespace Fintype section OrderedCommMonoid variable [Fintype ΞΉ] [OrderedCommMonoid M] {f : ΞΉ β†’ M} @[to_additive (attr := mono) sum_mono] theorem prod_mono' : Monotone fun f : ΞΉ β†’ M ↦ ∏ i, f i := fun _ _ hfg ↦ Finset.prod_le_prod' fun x _ ↦ hfg x #align fintype.prod_mono' Fintype.prod_mono' #align fintype.sum_mono Fintype.sum_mono @[to_additive sum_nonneg] lemma one_le_prod (hf : 1 ≀ f) : 1 ≀ ∏ i, f i := Finset.one_le_prod' Ξ» _ _ ↦ hf _ @[to_additive] lemma prod_le_one (hf : f ≀ 1) : ∏ i, f i ≀ 1 := Finset.prod_le_one' Ξ» _ _ ↦ hf _ end OrderedCommMonoid section OrderedCancelCommMonoid variable [Fintype ΞΉ] [OrderedCancelCommMonoid M] {f : ΞΉ β†’ M} @[to_additive sum_strictMono] theorem prod_strictMono' : StrictMono fun f : ΞΉ β†’ M ↦ ∏ x, f x := fun _ _ hfg ↦ let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩ #align fintype.prod_strict_mono' Fintype.prod_strictMono' #align fintype.sum_strict_mono Fintype.sum_strictMono @[to_additive sum_pos] lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i := Finset.one_lt_prod' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive] lemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 := Finset.prod_lt_one' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f := by obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod] @[to_additive] lemma prod_lt_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i < 1 ↔ f < 1 := by obtain rfl | hf := hf.eq_or_lt <;>
simp [*, prod_lt_one]
@[to_additive] lemma prod_lt_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i < 1 ↔ f < 1 := by obtain rfl | hf := hf.eq_or_lt <;>
Mathlib.Algebra.BigOperators.Order.758_0.ewL52iF1Dz3xeLh
@[to_additive] lemma prod_lt_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i < 1 ↔ f < 1
Mathlib_Algebra_BigOperators_Order
case inr ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝¹ : Fintype ΞΉ inst✝ : OrderedCancelCommMonoid M f : ΞΉ β†’ M hf✝ : f ≀ 1 hf : f < 1 ⊒ ∏ i : ΞΉ, f i < 1 ↔ f < 1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;> assumption #align finset.prod_add_prod_le' Finset.prod_add_prod_le' end CanonicallyOrderedCommSemiring end Finset namespace Fintype section OrderedCommMonoid variable [Fintype ΞΉ] [OrderedCommMonoid M] {f : ΞΉ β†’ M} @[to_additive (attr := mono) sum_mono] theorem prod_mono' : Monotone fun f : ΞΉ β†’ M ↦ ∏ i, f i := fun _ _ hfg ↦ Finset.prod_le_prod' fun x _ ↦ hfg x #align fintype.prod_mono' Fintype.prod_mono' #align fintype.sum_mono Fintype.sum_mono @[to_additive sum_nonneg] lemma one_le_prod (hf : 1 ≀ f) : 1 ≀ ∏ i, f i := Finset.one_le_prod' Ξ» _ _ ↦ hf _ @[to_additive] lemma prod_le_one (hf : f ≀ 1) : ∏ i, f i ≀ 1 := Finset.prod_le_one' Ξ» _ _ ↦ hf _ end OrderedCommMonoid section OrderedCancelCommMonoid variable [Fintype ΞΉ] [OrderedCancelCommMonoid M] {f : ΞΉ β†’ M} @[to_additive sum_strictMono] theorem prod_strictMono' : StrictMono fun f : ΞΉ β†’ M ↦ ∏ x, f x := fun _ _ hfg ↦ let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩ #align fintype.prod_strict_mono' Fintype.prod_strictMono' #align fintype.sum_strict_mono Fintype.sum_strictMono @[to_additive sum_pos] lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i := Finset.one_lt_prod' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive] lemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 := Finset.prod_lt_one' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f := by obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod] @[to_additive] lemma prod_lt_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i < 1 ↔ f < 1 := by obtain rfl | hf := hf.eq_or_lt <;>
simp [*, prod_lt_one]
@[to_additive] lemma prod_lt_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i < 1 ↔ f < 1 := by obtain rfl | hf := hf.eq_or_lt <;>
Mathlib.Algebra.BigOperators.Order.758_0.ewL52iF1Dz3xeLh
@[to_additive] lemma prod_lt_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i < 1 ↔ f < 1
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝¹ : Fintype ΞΉ inst✝ : OrderedCancelCommMonoid M f : ΞΉ β†’ M hf : 1 ≀ f ⊒ ∏ i : ΞΉ, f i = 1 ↔ f = 1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;> assumption #align finset.prod_add_prod_le' Finset.prod_add_prod_le' end CanonicallyOrderedCommSemiring end Finset namespace Fintype section OrderedCommMonoid variable [Fintype ΞΉ] [OrderedCommMonoid M] {f : ΞΉ β†’ M} @[to_additive (attr := mono) sum_mono] theorem prod_mono' : Monotone fun f : ΞΉ β†’ M ↦ ∏ i, f i := fun _ _ hfg ↦ Finset.prod_le_prod' fun x _ ↦ hfg x #align fintype.prod_mono' Fintype.prod_mono' #align fintype.sum_mono Fintype.sum_mono @[to_additive sum_nonneg] lemma one_le_prod (hf : 1 ≀ f) : 1 ≀ ∏ i, f i := Finset.one_le_prod' Ξ» _ _ ↦ hf _ @[to_additive] lemma prod_le_one (hf : f ≀ 1) : ∏ i, f i ≀ 1 := Finset.prod_le_one' Ξ» _ _ ↦ hf _ end OrderedCommMonoid section OrderedCancelCommMonoid variable [Fintype ΞΉ] [OrderedCancelCommMonoid M] {f : ΞΉ β†’ M} @[to_additive sum_strictMono] theorem prod_strictMono' : StrictMono fun f : ΞΉ β†’ M ↦ ∏ x, f x := fun _ _ hfg ↦ let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩ #align fintype.prod_strict_mono' Fintype.prod_strictMono' #align fintype.sum_strict_mono Fintype.sum_strictMono @[to_additive sum_pos] lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i := Finset.one_lt_prod' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive] lemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 := Finset.prod_lt_one' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f := by obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod] @[to_additive] lemma prod_lt_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i < 1 ↔ f < 1 := by obtain rfl | hf := hf.eq_or_lt <;> simp [*, prod_lt_one] @[to_additive] lemma prod_eq_one_iff_of_one_le (hf : 1 ≀ f) : ∏ i, f i = 1 ↔ f = 1 := by
simpa only [(one_le_prod hf).not_gt_iff_eq, hf.not_gt_iff_eq] using (one_lt_prod_iff_of_one_le hf).not
@[to_additive] lemma prod_eq_one_iff_of_one_le (hf : 1 ≀ f) : ∏ i, f i = 1 ↔ f = 1 := by
Mathlib.Algebra.BigOperators.Order.762_0.ewL52iF1Dz3xeLh
@[to_additive] lemma prod_eq_one_iff_of_one_le (hf : 1 ≀ f) : ∏ i, f i = 1 ↔ f = 1
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝¹ : Fintype ΞΉ inst✝ : OrderedCancelCommMonoid M f : ΞΉ β†’ M hf : f ≀ 1 ⊒ ∏ i : ΞΉ, f i = 1 ↔ f = 1
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;> assumption #align finset.prod_add_prod_le' Finset.prod_add_prod_le' end CanonicallyOrderedCommSemiring end Finset namespace Fintype section OrderedCommMonoid variable [Fintype ΞΉ] [OrderedCommMonoid M] {f : ΞΉ β†’ M} @[to_additive (attr := mono) sum_mono] theorem prod_mono' : Monotone fun f : ΞΉ β†’ M ↦ ∏ i, f i := fun _ _ hfg ↦ Finset.prod_le_prod' fun x _ ↦ hfg x #align fintype.prod_mono' Fintype.prod_mono' #align fintype.sum_mono Fintype.sum_mono @[to_additive sum_nonneg] lemma one_le_prod (hf : 1 ≀ f) : 1 ≀ ∏ i, f i := Finset.one_le_prod' Ξ» _ _ ↦ hf _ @[to_additive] lemma prod_le_one (hf : f ≀ 1) : ∏ i, f i ≀ 1 := Finset.prod_le_one' Ξ» _ _ ↦ hf _ end OrderedCommMonoid section OrderedCancelCommMonoid variable [Fintype ΞΉ] [OrderedCancelCommMonoid M] {f : ΞΉ β†’ M} @[to_additive sum_strictMono] theorem prod_strictMono' : StrictMono fun f : ΞΉ β†’ M ↦ ∏ x, f x := fun _ _ hfg ↦ let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩ #align fintype.prod_strict_mono' Fintype.prod_strictMono' #align fintype.sum_strict_mono Fintype.sum_strictMono @[to_additive sum_pos] lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i := Finset.one_lt_prod' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive] lemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 := Finset.prod_lt_one' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f := by obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod] @[to_additive] lemma prod_lt_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i < 1 ↔ f < 1 := by obtain rfl | hf := hf.eq_or_lt <;> simp [*, prod_lt_one] @[to_additive] lemma prod_eq_one_iff_of_one_le (hf : 1 ≀ f) : ∏ i, f i = 1 ↔ f = 1 := by simpa only [(one_le_prod hf).not_gt_iff_eq, hf.not_gt_iff_eq] using (one_lt_prod_iff_of_one_le hf).not @[to_additive] lemma prod_eq_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i = 1 ↔ f = 1 := by
simpa only [(prod_le_one hf).not_gt_iff_eq, hf.not_gt_iff_eq, eq_comm] using (prod_lt_one_iff_of_le_one hf).not
@[to_additive] lemma prod_eq_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i = 1 ↔ f = 1 := by
Mathlib.Algebra.BigOperators.Order.767_0.ewL52iF1Dz3xeLh
@[to_additive] lemma prod_eq_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i = 1 ↔ f = 1
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : AddCommMonoid M s : Finset ΞΉ f : ΞΉ β†’ WithTop M ⊒ βˆ‘ i in s, f i = ⊀ ↔ βˆƒ i ∈ s, f i = ⊀
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;> assumption #align finset.prod_add_prod_le' Finset.prod_add_prod_le' end CanonicallyOrderedCommSemiring end Finset namespace Fintype section OrderedCommMonoid variable [Fintype ΞΉ] [OrderedCommMonoid M] {f : ΞΉ β†’ M} @[to_additive (attr := mono) sum_mono] theorem prod_mono' : Monotone fun f : ΞΉ β†’ M ↦ ∏ i, f i := fun _ _ hfg ↦ Finset.prod_le_prod' fun x _ ↦ hfg x #align fintype.prod_mono' Fintype.prod_mono' #align fintype.sum_mono Fintype.sum_mono @[to_additive sum_nonneg] lemma one_le_prod (hf : 1 ≀ f) : 1 ≀ ∏ i, f i := Finset.one_le_prod' Ξ» _ _ ↦ hf _ @[to_additive] lemma prod_le_one (hf : f ≀ 1) : ∏ i, f i ≀ 1 := Finset.prod_le_one' Ξ» _ _ ↦ hf _ end OrderedCommMonoid section OrderedCancelCommMonoid variable [Fintype ΞΉ] [OrderedCancelCommMonoid M] {f : ΞΉ β†’ M} @[to_additive sum_strictMono] theorem prod_strictMono' : StrictMono fun f : ΞΉ β†’ M ↦ ∏ x, f x := fun _ _ hfg ↦ let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩ #align fintype.prod_strict_mono' Fintype.prod_strictMono' #align fintype.sum_strict_mono Fintype.sum_strictMono @[to_additive sum_pos] lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i := Finset.one_lt_prod' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive] lemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 := Finset.prod_lt_one' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f := by obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod] @[to_additive] lemma prod_lt_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i < 1 ↔ f < 1 := by obtain rfl | hf := hf.eq_or_lt <;> simp [*, prod_lt_one] @[to_additive] lemma prod_eq_one_iff_of_one_le (hf : 1 ≀ f) : ∏ i, f i = 1 ↔ f = 1 := by simpa only [(one_le_prod hf).not_gt_iff_eq, hf.not_gt_iff_eq] using (one_lt_prod_iff_of_one_le hf).not @[to_additive] lemma prod_eq_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i = 1 ↔ f = 1 := by simpa only [(prod_le_one hf).not_gt_iff_eq, hf.not_gt_iff_eq, eq_comm] using (prod_lt_one_iff_of_le_one hf).not end OrderedCancelCommMonoid end Fintype namespace WithTop open Finset /-- A product of finite numbers is still finite -/ theorem prod_lt_top [CommMonoidWithZero R] [NoZeroDivisors R] [Nontrivial R] [DecidableEq R] [LT R] {s : Finset ΞΉ} {f : ΞΉ β†’ WithTop R} (h : βˆ€ i ∈ s, f i β‰  ⊀) : ∏ i in s, f i < ⊀ := prod_induction f (fun a ↦ a < ⊀) (fun _ _ h₁ hβ‚‚ ↦ mul_lt_top' h₁ hβ‚‚) (coe_lt_top 1) fun a ha ↦ WithTop.lt_top_iff_ne_top.2 (h a ha) #align with_top.prod_lt_top WithTop.prod_lt_top /-- A sum of numbers is infinite iff one of them is infinite -/ theorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ΞΉ} {f : ΞΉ β†’ WithTop M} : βˆ‘ i in s, f i = ⊀ ↔ βˆƒ i ∈ s, f i = ⊀ := by
induction s using Finset.cons_induction
/-- A sum of numbers is infinite iff one of them is infinite -/ theorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ΞΉ} {f : ΞΉ β†’ WithTop M} : βˆ‘ i in s, f i = ⊀ ↔ βˆƒ i ∈ s, f i = ⊀ := by
Mathlib.Algebra.BigOperators.Order.786_0.ewL52iF1Dz3xeLh
/-- A sum of numbers is infinite iff one of them is infinite -/ theorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ΞΉ} {f : ΞΉ β†’ WithTop M} : βˆ‘ i in s, f i = ⊀ ↔ βˆƒ i ∈ s, f i = ⊀
Mathlib_Algebra_BigOperators_Order
case empty ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : AddCommMonoid M f : ΞΉ β†’ WithTop M ⊒ βˆ‘ i in βˆ…, f i = ⊀ ↔ βˆƒ i ∈ βˆ…, f i = ⊀
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;> assumption #align finset.prod_add_prod_le' Finset.prod_add_prod_le' end CanonicallyOrderedCommSemiring end Finset namespace Fintype section OrderedCommMonoid variable [Fintype ΞΉ] [OrderedCommMonoid M] {f : ΞΉ β†’ M} @[to_additive (attr := mono) sum_mono] theorem prod_mono' : Monotone fun f : ΞΉ β†’ M ↦ ∏ i, f i := fun _ _ hfg ↦ Finset.prod_le_prod' fun x _ ↦ hfg x #align fintype.prod_mono' Fintype.prod_mono' #align fintype.sum_mono Fintype.sum_mono @[to_additive sum_nonneg] lemma one_le_prod (hf : 1 ≀ f) : 1 ≀ ∏ i, f i := Finset.one_le_prod' Ξ» _ _ ↦ hf _ @[to_additive] lemma prod_le_one (hf : f ≀ 1) : ∏ i, f i ≀ 1 := Finset.prod_le_one' Ξ» _ _ ↦ hf _ end OrderedCommMonoid section OrderedCancelCommMonoid variable [Fintype ΞΉ] [OrderedCancelCommMonoid M] {f : ΞΉ β†’ M} @[to_additive sum_strictMono] theorem prod_strictMono' : StrictMono fun f : ΞΉ β†’ M ↦ ∏ x, f x := fun _ _ hfg ↦ let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩ #align fintype.prod_strict_mono' Fintype.prod_strictMono' #align fintype.sum_strict_mono Fintype.sum_strictMono @[to_additive sum_pos] lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i := Finset.one_lt_prod' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive] lemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 := Finset.prod_lt_one' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f := by obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod] @[to_additive] lemma prod_lt_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i < 1 ↔ f < 1 := by obtain rfl | hf := hf.eq_or_lt <;> simp [*, prod_lt_one] @[to_additive] lemma prod_eq_one_iff_of_one_le (hf : 1 ≀ f) : ∏ i, f i = 1 ↔ f = 1 := by simpa only [(one_le_prod hf).not_gt_iff_eq, hf.not_gt_iff_eq] using (one_lt_prod_iff_of_one_le hf).not @[to_additive] lemma prod_eq_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i = 1 ↔ f = 1 := by simpa only [(prod_le_one hf).not_gt_iff_eq, hf.not_gt_iff_eq, eq_comm] using (prod_lt_one_iff_of_le_one hf).not end OrderedCancelCommMonoid end Fintype namespace WithTop open Finset /-- A product of finite numbers is still finite -/ theorem prod_lt_top [CommMonoidWithZero R] [NoZeroDivisors R] [Nontrivial R] [DecidableEq R] [LT R] {s : Finset ΞΉ} {f : ΞΉ β†’ WithTop R} (h : βˆ€ i ∈ s, f i β‰  ⊀) : ∏ i in s, f i < ⊀ := prod_induction f (fun a ↦ a < ⊀) (fun _ _ h₁ hβ‚‚ ↦ mul_lt_top' h₁ hβ‚‚) (coe_lt_top 1) fun a ha ↦ WithTop.lt_top_iff_ne_top.2 (h a ha) #align with_top.prod_lt_top WithTop.prod_lt_top /-- A sum of numbers is infinite iff one of them is infinite -/ theorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ΞΉ} {f : ΞΉ β†’ WithTop M} : βˆ‘ i in s, f i = ⊀ ↔ βˆƒ i ∈ s, f i = ⊀ := by induction s using Finset.cons_induction <;>
simp [*]
/-- A sum of numbers is infinite iff one of them is infinite -/ theorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ΞΉ} {f : ΞΉ β†’ WithTop M} : βˆ‘ i in s, f i = ⊀ ↔ βˆƒ i ∈ s, f i = ⊀ := by induction s using Finset.cons_induction <;>
Mathlib.Algebra.BigOperators.Order.786_0.ewL52iF1Dz3xeLh
/-- A sum of numbers is infinite iff one of them is infinite -/ theorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ΞΉ} {f : ΞΉ β†’ WithTop M} : βˆ‘ i in s, f i = ⊀ ↔ βˆƒ i ∈ s, f i = ⊀
Mathlib_Algebra_BigOperators_Order
case cons ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝ : AddCommMonoid M f : ΞΉ β†’ WithTop M a✝¹ : ΞΉ s✝ : Finset ΞΉ h✝ : a✝¹ βˆ‰ s✝ a✝ : βˆ‘ i in s✝, f i = ⊀ ↔ βˆƒ i ∈ s✝, f i = ⊀ ⊒ βˆ‘ i in cons a✝¹ s✝ h✝, f i = ⊀ ↔ βˆƒ i ∈ cons a✝¹ s✝ h✝, f i = ⊀
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;> assumption #align finset.prod_add_prod_le' Finset.prod_add_prod_le' end CanonicallyOrderedCommSemiring end Finset namespace Fintype section OrderedCommMonoid variable [Fintype ΞΉ] [OrderedCommMonoid M] {f : ΞΉ β†’ M} @[to_additive (attr := mono) sum_mono] theorem prod_mono' : Monotone fun f : ΞΉ β†’ M ↦ ∏ i, f i := fun _ _ hfg ↦ Finset.prod_le_prod' fun x _ ↦ hfg x #align fintype.prod_mono' Fintype.prod_mono' #align fintype.sum_mono Fintype.sum_mono @[to_additive sum_nonneg] lemma one_le_prod (hf : 1 ≀ f) : 1 ≀ ∏ i, f i := Finset.one_le_prod' Ξ» _ _ ↦ hf _ @[to_additive] lemma prod_le_one (hf : f ≀ 1) : ∏ i, f i ≀ 1 := Finset.prod_le_one' Ξ» _ _ ↦ hf _ end OrderedCommMonoid section OrderedCancelCommMonoid variable [Fintype ΞΉ] [OrderedCancelCommMonoid M] {f : ΞΉ β†’ M} @[to_additive sum_strictMono] theorem prod_strictMono' : StrictMono fun f : ΞΉ β†’ M ↦ ∏ x, f x := fun _ _ hfg ↦ let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩ #align fintype.prod_strict_mono' Fintype.prod_strictMono' #align fintype.sum_strict_mono Fintype.sum_strictMono @[to_additive sum_pos] lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i := Finset.one_lt_prod' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive] lemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 := Finset.prod_lt_one' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f := by obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod] @[to_additive] lemma prod_lt_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i < 1 ↔ f < 1 := by obtain rfl | hf := hf.eq_or_lt <;> simp [*, prod_lt_one] @[to_additive] lemma prod_eq_one_iff_of_one_le (hf : 1 ≀ f) : ∏ i, f i = 1 ↔ f = 1 := by simpa only [(one_le_prod hf).not_gt_iff_eq, hf.not_gt_iff_eq] using (one_lt_prod_iff_of_one_le hf).not @[to_additive] lemma prod_eq_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i = 1 ↔ f = 1 := by simpa only [(prod_le_one hf).not_gt_iff_eq, hf.not_gt_iff_eq, eq_comm] using (prod_lt_one_iff_of_le_one hf).not end OrderedCancelCommMonoid end Fintype namespace WithTop open Finset /-- A product of finite numbers is still finite -/ theorem prod_lt_top [CommMonoidWithZero R] [NoZeroDivisors R] [Nontrivial R] [DecidableEq R] [LT R] {s : Finset ΞΉ} {f : ΞΉ β†’ WithTop R} (h : βˆ€ i ∈ s, f i β‰  ⊀) : ∏ i in s, f i < ⊀ := prod_induction f (fun a ↦ a < ⊀) (fun _ _ h₁ hβ‚‚ ↦ mul_lt_top' h₁ hβ‚‚) (coe_lt_top 1) fun a ha ↦ WithTop.lt_top_iff_ne_top.2 (h a ha) #align with_top.prod_lt_top WithTop.prod_lt_top /-- A sum of numbers is infinite iff one of them is infinite -/ theorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ΞΉ} {f : ΞΉ β†’ WithTop M} : βˆ‘ i in s, f i = ⊀ ↔ βˆƒ i ∈ s, f i = ⊀ := by induction s using Finset.cons_induction <;>
simp [*]
/-- A sum of numbers is infinite iff one of them is infinite -/ theorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ΞΉ} {f : ΞΉ β†’ WithTop M} : βˆ‘ i in s, f i = ⊀ ↔ βˆƒ i ∈ s, f i = ⊀ := by induction s using Finset.cons_induction <;>
Mathlib.Algebra.BigOperators.Order.786_0.ewL52iF1Dz3xeLh
/-- A sum of numbers is infinite iff one of them is infinite -/ theorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ΞΉ} {f : ΞΉ β†’ WithTop M} : βˆ‘ i in s, f i = ⊀ ↔ βˆƒ i ∈ s, f i = ⊀
Mathlib_Algebra_BigOperators_Order
ΞΉ : Type u_1 Ξ± : Type u_2 Ξ² : Type u_3 M : Type u_4 N : Type u_5 G : Type u_6 k : Type u_7 R : Type u_8 inst✝¹ : AddCommMonoid M inst✝ : LT M s : Finset ΞΉ f : ΞΉ β†’ WithTop M ⊒ βˆ‘ i in s, f i < ⊀ ↔ βˆ€ i ∈ s, f i < ⊀
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Tactic.GCongr.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Results about big operators with values in an ordered algebraic structure. Mostly monotonicity results for the `∏` and `βˆ‘` operations. -/ open Function open BigOperators variable {ΞΉ Ξ± Ξ² M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map submultiplicative on `{x | p x}`, i.e., `p x β†’ p y β†’ f (x * y) ≀ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ x in s, g x) ≀ ∏ x in s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) (s : Finset ΞΉ) (hs_nonempty : s.Nonempty) (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _ Β· simp [hs_nonempty.ne_empty] Β· exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `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 `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M β†’ N) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) {s : Finset ΞΉ} (hs : s.Nonempty) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M β†’ N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `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 that `βˆ€ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M β†’ N) (p : M β†’ Prop) (h_one : f 1 = 1) (h_mul : βˆ€ x y, p x β†’ p y β†’ f (x * y) ≀ f x * f y) (hp_mul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (g : ΞΉ β†’ M) {s : Finset ΞΉ} (hs : βˆ€ i ∈ s, p (g i)) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) Β· simp [h_one] Β· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M β†’ N` be a map such 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`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `βˆ€ i ∈ s, p (g i)`. Then `f (βˆ‘ x in s, g x) ≀ βˆ‘ x in s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M β†’ N` is a submultiplicative function, `f (x * y) ≀ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≀ ∏ i in s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M β†’ N) (h_one : f 1 = 1) (h_mul : βˆ€ x y, f (x * y) ≀ f x * f y) (s : Finset ΞΉ) (g : ΞΉ β†’ M) : f (∏ i in s, g i) ≀ ∏ i in s, f (g i) := by refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M β†’ N` is a subadditive function, `f (x + y) ≀ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (βˆ‘ i in s, g i) ≀ βˆ‘ i in s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ΞΉ β†’ N} {s t : Finset ΞΉ} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i in s, f i ≀ ∏ i in s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `βˆ‘ i in s, f i ≀ βˆ‘ i in s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≀ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≀ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) : 1 ≀ ∏ i in s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : βˆ€ i : ΞΉ, 1 ≀ f i) : 1 ≀ ∏ i : ΞΉ in s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s βŠ† t) (hf : βˆ€ i ∈ t, i βˆ‰ s β†’ 1 ≀ f i) : ∏ i in s, f i ≀ ∏ i in t, f i := by classical calc ∏ i in s, f i ≀ (∏ i in t \ s, f i) * ∏ i in s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i in t \ s βˆͺ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : βˆ€ x, 1 ≀ f x) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ΞΉ] {s : Finset ΞΉ} (w : βˆ€ x, 1 ≀ f x) : ∏ x in s, f x ≀ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting Note: TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (βˆ€ i ∈ s, 1 ≀ f i) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : βˆ€ i ∈ s, 1 ≀ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive existing sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_le_one' : (βˆ€ i ∈ s, f i ≀ 1) β†’ ((∏ i in s, f i) = 1 ↔ βˆ€ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nα΅’α΅ˆ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' -- Porting note: there is no align for the additive version since it aligns to the -- same one as the previous lemma @[to_additive single_le_sum] theorem single_le_prod' (hf : βˆ€ i ∈ s, 1 ≀ f i) {a} (h : a ∈ s) : f a ≀ ∏ x in s, f x := calc f a = ∏ i in {a}, f i := (prod_singleton _ _).symm _ ≀ ∏ i in s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ΞΉ} (hf : βˆ€ i ∈ s, 1 ≀ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i β‰  j) : f i * f j ≀ ∏ k in s, f k := calc f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≀ ∏ k in s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, f x ≀ n) : s.prod f ≀ n ^ s.card := by refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _ Β· simpa using h Β· simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ΞΉ) (f : ΞΉ β†’ N) (n : N) (h : βˆ€ x ∈ s, n ≀ f x) : n ^ s.card ≀ s.prod f := @Finset.prod_le_pow_card _ Nα΅’α΅ˆ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq Ξ²] (s : Finset ΞΉ) (f : ΞΉ β†’ Finset Ξ²) (n : β„•) (h : βˆ€ a ∈ s, (f a).card ≀ n) : (s.biUnion f).card ≀ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ΞΉ' : Type*} [DecidableEq ΞΉ'] -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, (1 : N) ≀ ∏ x in s.filter fun x ↦ g x = y, f x) : (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ x in s, f x := calc (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≀ ∏ y in t βˆͺ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y _ = ∏ x in s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y Β«expr βˆ‰ Β» t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ΞΉ'} {g : ΞΉ β†’ ΞΉ'} {f : ΞΉ β†’ N} (h : βˆ€ y βˆ‰ t, ∏ x in s.filter fun x ↦ g x = y, f x ≀ 1) : ∏ x in s, f x ≀ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nα΅’α΅ˆ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ΞΉ β†’ G) (s : Finset ΞΉ) : |βˆ‘ i in s, f i| ≀ βˆ‘ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i ∈ s, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ΞΉ β†’ G} {s : Finset ΞΉ} (hf : βˆ€ i, 0 ≀ f i) : |βˆ‘ i : ΞΉ in s, f i| = βˆ‘ i : ΞΉ in s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' theorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ΞΉ β†’ R} {s : Finset ΞΉ} : |∏ x in s, f x| = ∏ x in s, |f x| := map_prod absHom _ _ #align finset.abs_prod Finset.abs_prod section Pigeonhole variable [DecidableEq Ξ²] theorem card_le_mul_card_image_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * t.card := calc s.card = βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≀ βˆ‘ _a in t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≀ n) : s.card ≀ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Finset Ξ²} (Hf : βˆ€ a ∈ s, f a ∈ t) (n : β„•) (hn : βˆ€ a ∈ t, n ≀ (s.filter fun x ↦ f x = a).card) : n * t.card ≀ s.card := calc n * t.card = βˆ‘ _a in t, n := by simp [mul_comm] _ ≀ βˆ‘ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : Ξ± β†’ Ξ²} (s : Finset Ξ±) (n : β„•) (hn : βˆ€ a ∈ s.image f, n ≀ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≀ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq Ξ±] {s : Finset Ξ±} {B : Finset (Finset Ξ±)} {n : β„•} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card ≀ n) : (βˆ‘ t in B, (s ∩ t).card) ≀ s.card * n := by refine' le_trans _ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card ≀ n) : βˆ‘ s in B, s.card ≀ Fintype.card Ξ± * n := calc βˆ‘ s in B, s.card = βˆ‘ s in B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≀ Fintype.card Ξ± * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : βˆ€ a ∈ s, n ≀ (B.filter (a ∈ Β·)).card) : s.card * n ≀ βˆ‘ t in B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card [Fintype Ξ±] (h : βˆ€ a, n ≀ (B.filter (a ∈ Β·)).card) : Fintype.card Ξ± * n ≀ βˆ‘ s in B, s.card := calc Fintype.card Ξ± * n ≀ βˆ‘ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = βˆ‘ s in B, s.card := by simp_rw [univ_inter] #align finset.le_sum_card Finset.le_sum_card /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card_inter (h : βˆ€ a ∈ s, (B.filter (a ∈ Β·)).card = n) : (βˆ‘ t in B, (s ∩ t).card) = s.card * n := (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge) #align finset.sum_card_inter Finset.sum_card_inter /-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how many they are. -/ theorem sum_card [Fintype Ξ±] (h : βˆ€ a, (B.filter (a ∈ Β·)).card = n) : βˆ‘ s in B, s.card = Fintype.card Ξ± * n := by simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter] #align finset.sum_card Finset.sum_card theorem card_le_card_biUnion {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) (hf : βˆ€ i ∈ s, (f i).Nonempty) : s.card ≀ (s.biUnion f).card := by rw [card_biUnion hs, card_eq_sum_ones] exact sum_le_sum fun i hi ↦ (hf i hi).card_pos #align finset.card_le_card_bUnion Finset.card_le_card_biUnion theorem card_le_card_biUnion_add_card_fiber {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + (s.filter fun i ↦ f i = βˆ…).card := by rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = βˆ…, add_comm] exact add_le_add_right ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦ nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <| card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _) _ #align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber theorem card_le_card_biUnion_add_one {s : Finset ΞΉ} {f : ΞΉ β†’ Finset Ξ±} (hf : Injective f) (hs : (s : Set ΞΉ).PairwiseDisjoint f) : s.card ≀ (s.biUnion f).card + 1 := (card_le_card_biUnion_add_card_fiber hs).trans <| add_le_add_left (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _ #align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one end DoubleCounting section CanonicallyOrderedCommMonoid variable [CanonicallyOrderedCommMonoid M] {f : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive (attr := simp) sum_eq_zero_iff] theorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ βˆ€ x ∈ s, f x = 1 := prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x) #align finset.prod_eq_one_iff' Finset.prod_eq_one_iff' #align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff @[to_additive sum_le_sum_of_subset] theorem prod_le_prod_of_subset' (h : s βŠ† t) : ∏ x in s, f x ≀ ∏ x in t, f x := prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _ #align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset' #align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset @[to_additive sum_mono_set] theorem prod_mono_set' (f : ΞΉ β†’ M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦ prod_le_prod_of_subset' hs #align finset.prod_mono_set' Finset.prod_mono_set' #align finset.sum_mono_set Finset.sum_mono_set @[to_additive sum_le_sum_of_ne_zero] theorem prod_le_prod_of_ne_one' (h : βˆ€ x ∈ s, f x β‰  1 β†’ x ∈ t) : ∏ x in s, f x ≀ ∏ x in t, f x := by classical calc ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) * ∏ x in s.filter fun x ↦ f x β‰  1, f x := by rw [← prod_union, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h _ ≀ ∏ x in t, f x := mul_le_of_le_one_of_le (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq) (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] ) #align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one' #align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero end CanonicallyOrderedCommMonoid section OrderedCancelCommMonoid variable [OrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive sum_lt_sum] theorem prod_lt_prod' (hle : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod' hle hlt #align finset.prod_lt_prod' Finset.prod_lt_prod' #align finset.sum_lt_sum Finset.sum_lt_sum @[to_additive sum_lt_sum_of_nonempty] theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : βˆ€ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt #align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty' #align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty /-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is strictly less than the corresponding factor `g i` of another nontrivial finite product, then `s.prod f < s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty] theorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : βˆ€ i ∈ s, f i < g i) : s.prod f < s.prod g := s.prod_lt_prod_of_nonempty' hs Hlt /-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is strictly less than the corresponding summand `g i` of another nontrivial finite sum, then `s.sum f < s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_lt_sum_of_nonempty -- Porting note: TODO -- calc indentation @[to_additive sum_lt_sum_of_subset] theorem prod_lt_prod_of_subset' (h : s βŠ† t) {i : ΞΉ} (ht : i ∈ t) (hs : i βˆ‰ s) (hlt : 1 < f i) (hle : βˆ€ j ∈ t, j βˆ‰ s β†’ 1 ≀ f j) : ∏ j in s, f j < ∏ j in t, f j := by classical calc ∏ j in s, f j < ∏ j in insert i s, f j := by rw [prod_insert hs] exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt _ ≀ ∏ j in t, f j := by apply prod_le_prod_of_subset_of_one_le' Β· simp [Finset.insert_subset_iff, h, ht] Β· intro x hx h'x simp only [mem_insert, not_or] at h'x exact hle x hx h'x.2 #align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset' #align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset @[to_additive single_lt_sum] theorem single_lt_prod' {i j : ΞΉ} (hij : j β‰  i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j) (hle : βˆ€ k ∈ s, k β‰  i β†’ 1 ≀ f k) : f i < ∏ k in s, f k := calc f i = ∏ k in {i}, f k := by rw [prod_singleton] _ < ∏ k in s, f k := prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki) #align finset.single_lt_prod' Finset.single_lt_prod' #align finset.single_lt_sum Finset.single_lt_sum @[to_additive sum_pos] theorem one_lt_prod (h : βˆ€ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i := lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h #align finset.one_lt_prod Finset.one_lt_prod #align finset.sum_pos Finset.sum_pos @[to_additive] theorem prod_lt_one (h : βˆ€ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 := (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one]) #align finset.prod_lt_one Finset.prod_lt_one #align finset.sum_neg Finset.sum_neg @[to_additive sum_pos'] theorem one_lt_prod' (h : βˆ€ i ∈ s, 1 ≀ f i) (hs : βˆƒ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i := prod_const_one.symm.trans_lt <| prod_lt_prod' h hs #align finset.one_lt_prod' Finset.one_lt_prod' #align finset.sum_pos' Finset.sum_pos' @[to_additive] theorem prod_lt_one' (h : βˆ€ i ∈ s, f i ≀ 1) (hs : βˆƒ i ∈ s, f i < 1) : ∏ i in s, f i < 1 := prod_const_one.le.trans_lt' <| prod_lt_prod' h hs #align finset.prod_lt_one' Finset.prod_lt_one' #align finset.sum_neg' Finset.sum_neg' @[to_additive] theorem prod_eq_prod_iff_of_le {f g : ΞΉ β†’ M} (h : βˆ€ i ∈ s, f i ≀ g i) : ((∏ i in s, f i) = ∏ i in s, g i) ↔ βˆ€ i ∈ s, f i = g i := by classical revert h refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_ specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih] exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem) #align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le #align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le variable [DecidableEq ΞΉ] @[to_additive] lemma prod_sdiff_le_prod_sdiff : ∏ i in s \ t, f i ≀ ∏ i in t \ s, f i ↔ ∏ i in s, f i ≀ ∏ i in t, f i := by rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s @[to_additive] lemma prod_sdiff_lt_prod_sdiff : ∏ i in s \ t, f i < ∏ i in t \ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter, ← prod_union, inter_comm, sdiff_union_inter]; simpa only [inter_comm] using disjoint_sdiff_inter t s end OrderedCancelCommMonoid section LinearOrderedCancelCommMonoid variable [LinearOrderedCancelCommMonoid M] {f g : ΞΉ β†’ M} {s t : Finset ΞΉ} @[to_additive exists_lt_of_sum_lt] theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : βˆƒ i ∈ s, f i < g i := by contrapose! Hlt with Hle exact prod_le_prod' Hle #align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt' #align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt @[to_additive exists_le_of_sum_le] theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≀ ∏ i in s, g i) : βˆƒ i ∈ s, f i ≀ g i := by contrapose! Hle with Hlt exact prod_lt_prod_of_nonempty' hs Hlt #align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le' #align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le @[to_additive exists_pos_of_sum_zero_of_exists_nonzero] theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ΞΉ β†’ M) (h₁ : ∏ i in s, f i = 1) (hβ‚‚ : βˆƒ i ∈ s, f i β‰  1) : βˆƒ i ∈ s, 1 < f i := by contrapose! h₁ obtain ⟨i, m, i_ne⟩ : βˆƒ i ∈ s, f i β‰  1 := hβ‚‚ apply ne_of_lt calc ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩ _ = 1 := prod_const_one #align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one' #align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero end LinearOrderedCancelCommMonoid section OrderedCommSemiring variable [OrderedCommSemiring R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} open Classical -- this is also true for an ordered commutative multiplicative monoid with zero theorem prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i in s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 #align finset.prod_nonneg Finset.prod_nonneg /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i in s, f i ≀ ∏ i in s, g i := by induction' s using Finset.induction with a s has ih h Β· simp Β· simp only [prod_insert has] apply mul_le_mul Β· exact h1 a (mem_insert_self a s) Β· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H Β· apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H) Β· apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) #align finset.prod_le_prod Finset.prod_le_prod /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient for the `gcongr` tactic. -/ @[gcongr] theorem _root_.GCongr.prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : s.prod f ≀ s.prod g := s.prod_le_prod h0 h1 /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ theorem prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i in s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one #align finset.prod_le_one Finset.prod_le_one /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/ theorem prod_add_prod_le {i : ΞΉ} {f g h : ΞΉ β†’ R} (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (hhf : βˆ€ j ∈ s, j β‰  i β†’ h j ≀ f j) (hg : βˆ€ i ∈ s, 0 ≀ g i) (hh : βˆ€ i ∈ s, 0 ≀ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≀ ∏ i in s, f i := by simp_rw [prod_eq_mul_prod_diff_singleton hi] refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_) Β· rw [right_distrib] refine add_le_add ?_ ?_ <;> Β· refine mul_le_mul_of_nonneg_left ?_ ?_ Β· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*] Β· try apply_assumption try assumption Β· apply prod_nonneg simp only [and_imp, mem_sdiff, mem_singleton] intro j h1j h2j exact le_trans (hg j h1j) (hgf j h1j h2j) #align finset.prod_add_prod_le Finset.prod_add_prod_le end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring R] {f g : ΞΉ β†’ R} {s : Finset ΞΉ} -- This is also true for an ordered commutative multiplicative monoid with zero theorem prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 #align finset.prod_pos Finset.prod_pos theorem prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i in s, f i < ∏ i in s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] apply mul_lt_mul hilt Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact le_of_lt <| (hf i hi).trans hilt theorem prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i in s, f i < ∏ i in s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end StrictOrderedCommSemiring section CanonicallyOrderedCommSemiring variable [CanonicallyOrderedCommSemiring R] {f g h : ΞΉ β†’ R} {s : Finset ΞΉ} {i : ΞΉ} /-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/ @[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] : 0 < ∏ i in s, f i ↔ (βˆ€ i ∈ s, (0 : R) < f i) := CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff #align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos /-- If `g, h ≀ f` and `g i + h i ≀ f i`, then the product of `f` over `s` is at least the sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`. -/ theorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≀ f i) (hgf : βˆ€ j ∈ s, j β‰  i β†’ g j ≀ f j) (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 classical simp_rw [prod_eq_mul_prod_diff_singleton hi] refine' le_trans _ (mul_le_mul_right' h2i _) rw [right_distrib] apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;> simp only [and_imp, mem_sdiff, mem_singleton] <;> intros <;> apply_assumption <;> assumption #align finset.prod_add_prod_le' Finset.prod_add_prod_le' end CanonicallyOrderedCommSemiring end Finset namespace Fintype section OrderedCommMonoid variable [Fintype ΞΉ] [OrderedCommMonoid M] {f : ΞΉ β†’ M} @[to_additive (attr := mono) sum_mono] theorem prod_mono' : Monotone fun f : ΞΉ β†’ M ↦ ∏ i, f i := fun _ _ hfg ↦ Finset.prod_le_prod' fun x _ ↦ hfg x #align fintype.prod_mono' Fintype.prod_mono' #align fintype.sum_mono Fintype.sum_mono @[to_additive sum_nonneg] lemma one_le_prod (hf : 1 ≀ f) : 1 ≀ ∏ i, f i := Finset.one_le_prod' Ξ» _ _ ↦ hf _ @[to_additive] lemma prod_le_one (hf : f ≀ 1) : ∏ i, f i ≀ 1 := Finset.prod_le_one' Ξ» _ _ ↦ hf _ end OrderedCommMonoid section OrderedCancelCommMonoid variable [Fintype ΞΉ] [OrderedCancelCommMonoid M] {f : ΞΉ β†’ M} @[to_additive sum_strictMono] theorem prod_strictMono' : StrictMono fun f : ΞΉ β†’ M ↦ ∏ x, f x := fun _ _ hfg ↦ let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩ #align fintype.prod_strict_mono' Fintype.prod_strictMono' #align fintype.sum_strict_mono Fintype.sum_strictMono @[to_additive sum_pos] lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i := Finset.one_lt_prod' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive] lemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 := Finset.prod_lt_one' (Ξ» _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2 @[to_additive sum_pos_iff_of_nonneg] lemma one_lt_prod_iff_of_one_le (hf : 1 ≀ f) : 1 < ∏ i, f i ↔ 1 < f := by obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod] @[to_additive] lemma prod_lt_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i < 1 ↔ f < 1 := by obtain rfl | hf := hf.eq_or_lt <;> simp [*, prod_lt_one] @[to_additive] lemma prod_eq_one_iff_of_one_le (hf : 1 ≀ f) : ∏ i, f i = 1 ↔ f = 1 := by simpa only [(one_le_prod hf).not_gt_iff_eq, hf.not_gt_iff_eq] using (one_lt_prod_iff_of_one_le hf).not @[to_additive] lemma prod_eq_one_iff_of_le_one (hf : f ≀ 1) : ∏ i, f i = 1 ↔ f = 1 := by simpa only [(prod_le_one hf).not_gt_iff_eq, hf.not_gt_iff_eq, eq_comm] using (prod_lt_one_iff_of_le_one hf).not end OrderedCancelCommMonoid end Fintype namespace WithTop open Finset /-- A product of finite numbers is still finite -/ theorem prod_lt_top [CommMonoidWithZero R] [NoZeroDivisors R] [Nontrivial R] [DecidableEq R] [LT R] {s : Finset ΞΉ} {f : ΞΉ β†’ WithTop R} (h : βˆ€ i ∈ s, f i β‰  ⊀) : ∏ i in s, f i < ⊀ := prod_induction f (fun a ↦ a < ⊀) (fun _ _ h₁ hβ‚‚ ↦ mul_lt_top' h₁ hβ‚‚) (coe_lt_top 1) fun a ha ↦ WithTop.lt_top_iff_ne_top.2 (h a ha) #align with_top.prod_lt_top WithTop.prod_lt_top /-- A sum of numbers is infinite iff one of them is infinite -/ theorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ΞΉ} {f : ΞΉ β†’ WithTop M} : βˆ‘ i in s, f i = ⊀ ↔ βˆƒ i ∈ s, f i = ⊀ := by induction s using Finset.cons_induction <;> simp [*] #align with_top.sum_eq_top_iff WithTop.sum_eq_top_iff /-- A sum of finite numbers is still finite -/ theorem sum_lt_top_iff [AddCommMonoid M] [LT M] {s : Finset ΞΉ} {f : ΞΉ β†’ WithTop M} : βˆ‘ i in s, f i < ⊀ ↔ βˆ€ i ∈ s, f i < ⊀ := by
simp only [WithTop.lt_top_iff_ne_top, ne_eq, sum_eq_top_iff, not_exists, not_and]
/-- A sum of finite numbers is still finite -/ theorem sum_lt_top_iff [AddCommMonoid M] [LT M] {s : Finset ΞΉ} {f : ΞΉ β†’ WithTop M} : βˆ‘ i in s, f i < ⊀ ↔ βˆ€ i ∈ s, f i < ⊀ := by
Mathlib.Algebra.BigOperators.Order.792_0.ewL52iF1Dz3xeLh
/-- A sum of finite numbers is still finite -/ theorem sum_lt_top_iff [AddCommMonoid M] [LT M] {s : Finset ΞΉ} {f : ΞΉ β†’ WithTop M} : βˆ‘ i in s, f i < ⊀ ↔ βˆ€ i ∈ s, f i < ⊀
Mathlib_Algebra_BigOperators_Order
b x y : ℝ ⊒ logb b 0 = 0
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by
simp [logb]
@[simp] theorem logb_zero : logb b 0 = 0 := by
Mathlib.Analysis.SpecialFunctions.Log.Base.48_0.egNyp4fdqSCAE7f
@[simp] theorem logb_zero : logb b 0 = 0
Mathlib_Analysis_SpecialFunctions_Log_Base
b x y : ℝ ⊒ logb b 1 = 0
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by
simp [logb]
@[simp] theorem logb_one : logb b 1 = 0 := by
Mathlib.Analysis.SpecialFunctions.Log.Base.52_0.egNyp4fdqSCAE7f
@[simp] theorem logb_one : logb b 1 = 0
Mathlib_Analysis_SpecialFunctions_Log_Base
b x y : ℝ h : logb b b = 1 h' : log b = 0 ⊒ False
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by
simp [logb, h'] at h
lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by
Mathlib.Analysis.SpecialFunctions.Log.Base.60_0.egNyp4fdqSCAE7f
lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1
Mathlib_Analysis_SpecialFunctions_Log_Base
b x✝ y x : ℝ ⊒ logb b |x| = logb b x
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by
rw [logb, logb, log_abs]
@[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by
Mathlib.Analysis.SpecialFunctions.Log.Base.63_0.egNyp4fdqSCAE7f
@[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x
Mathlib_Analysis_SpecialFunctions_Log_Base
b x✝ y x : ℝ ⊒ logb b (-x) = logb b x
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by
rw [← logb_abs x, ← logb_abs (-x), abs_neg]
@[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by
Mathlib.Analysis.SpecialFunctions.Log.Base.67_0.egNyp4fdqSCAE7f
@[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x
Mathlib_Analysis_SpecialFunctions_Log_Base
b x y : ℝ hx : x β‰  0 hy : y β‰  0 ⊒ logb b (x * y) = logb b x + logb b y
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by
simp_rw [logb, log_mul hx hy, add_div]
theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by
Mathlib.Analysis.SpecialFunctions.Log.Base.72_0.egNyp4fdqSCAE7f
theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y
Mathlib_Analysis_SpecialFunctions_Log_Base
b x y : ℝ hx : x β‰  0 hy : y β‰  0 ⊒ logb b (x / y) = logb b x - logb b y
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by
simp_rw [logb, log_div hx hy, sub_div]
theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by
Mathlib.Analysis.SpecialFunctions.Log.Base.76_0.egNyp4fdqSCAE7f
theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y
Mathlib_Analysis_SpecialFunctions_Log_Base
b x✝ y x : ℝ ⊒ logb b x⁻¹ = -logb b x
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by
simp [logb, neg_div]
@[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by
Mathlib.Analysis.SpecialFunctions.Log.Base.80_0.egNyp4fdqSCAE7f
@[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x
Mathlib_Analysis_SpecialFunctions_Log_Base
b✝ x y a b : ℝ ⊒ (logb a b)⁻¹ = logb b a
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by
simp_rw [logb, inv_div]
theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by
Mathlib.Analysis.SpecialFunctions.Log.Base.84_0.egNyp4fdqSCAE7f
theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a
Mathlib_Analysis_SpecialFunctions_Log_Base
b✝ x y a b : ℝ h₁ : a β‰  0 hβ‚‚ : b β‰  0 c : ℝ ⊒ (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by
simp_rw [inv_logb]
theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by
Mathlib.Analysis.SpecialFunctions.Log.Base.87_0.egNyp4fdqSCAE7f
theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹
Mathlib_Analysis_SpecialFunctions_Log_Base
b✝ x y a b : ℝ h₁ : a β‰  0 hβ‚‚ : b β‰  0 c : ℝ ⊒ logb c (a * b) = logb c a + logb c b
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb];
exact logb_mul h₁ hβ‚‚
theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb];
Mathlib.Analysis.SpecialFunctions.Log.Base.87_0.egNyp4fdqSCAE7f
theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹
Mathlib_Analysis_SpecialFunctions_Log_Base
b✝ x y a b : ℝ h₁ : a β‰  0 hβ‚‚ : b β‰  0 c : ℝ ⊒ (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by
simp_rw [inv_logb]
theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by
Mathlib.Analysis.SpecialFunctions.Log.Base.92_0.egNyp4fdqSCAE7f
theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹
Mathlib_Analysis_SpecialFunctions_Log_Base
b✝ x y a b : ℝ h₁ : a β‰  0 hβ‚‚ : b β‰  0 c : ℝ ⊒ logb c (a / b) = logb c a - logb c b
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb];
exact logb_div h₁ hβ‚‚
theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb];
Mathlib.Analysis.SpecialFunctions.Log.Base.92_0.egNyp4fdqSCAE7f
theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹
Mathlib_Analysis_SpecialFunctions_Log_Base
b✝ x y a b : ℝ h₁ : a β‰  0 hβ‚‚ : b β‰  0 c : ℝ ⊒ logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by
rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv]
theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by
Mathlib.Analysis.SpecialFunctions.Log.Base.97_0.egNyp4fdqSCAE7f
theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹
Mathlib_Analysis_SpecialFunctions_Log_Base
b✝ x y a b : ℝ h₁ : a β‰  0 hβ‚‚ : b β‰  0 c : ℝ ⊒ logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by
rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv]
theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by
Mathlib.Analysis.SpecialFunctions.Log.Base.101_0.egNyp4fdqSCAE7f
theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹
Mathlib_Analysis_SpecialFunctions_Log_Base
b✝ x y a b c : ℝ h₁ : b β‰  0 hβ‚‚ : b β‰  1 h₃ : b β‰  -1 ⊒ logb a b * logb b c = logb a c
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by
unfold logb
theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by
Mathlib.Analysis.SpecialFunctions.Log.Base.105_0.egNyp4fdqSCAE7f
theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c
Mathlib_Analysis_SpecialFunctions_Log_Base
b✝ x y a b c : ℝ h₁ : b β‰  0 hβ‚‚ : b β‰  1 h₃ : b β‰  -1 ⊒ log b / log a * (log c / log b) = log c / log a
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb
rw [mul_comm, div_mul_div_cancel _ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)]
theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb
Mathlib.Analysis.SpecialFunctions.Log.Base.105_0.egNyp4fdqSCAE7f
theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c
Mathlib_Analysis_SpecialFunctions_Log_Base
b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 ⊒ log b β‰  0
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel _ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)] #align real.mul_logb Real.mul_logb theorem div_logb {a b c : ℝ} (h₁ : c β‰  0) (hβ‚‚ : c β‰  1) (h₃ : c β‰  -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ© #align real.div_logb Real.div_logb section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b β‰  1) private theorem log_b_ne_zero : log b β‰  0 := by
have b_ne_zero : b β‰  0
private theorem log_b_ne_zero : log b β‰  0 := by
Mathlib.Analysis.SpecialFunctions.Log.Base.120_0.egNyp4fdqSCAE7f
private theorem log_b_ne_zero : log b β‰  0
Mathlib_Analysis_SpecialFunctions_Log_Base
case b_ne_zero b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 ⊒ b β‰  0 b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 b_ne_zero : b β‰  0 ⊒ log b β‰  0
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel _ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)] #align real.mul_logb Real.mul_logb theorem div_logb {a b c : ℝ} (h₁ : c β‰  0) (hβ‚‚ : c β‰  1) (h₃ : c β‰  -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ© #align real.div_logb Real.div_logb section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b β‰  1) private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0;
linarith
private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0;
Mathlib.Analysis.SpecialFunctions.Log.Base.120_0.egNyp4fdqSCAE7f
private theorem log_b_ne_zero : log b β‰  0
Mathlib_Analysis_SpecialFunctions_Log_Base
b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 b_ne_zero : b β‰  0 ⊒ log b β‰  0
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel _ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)] #align real.mul_logb Real.mul_logb theorem div_logb {a b c : ℝ} (h₁ : c β‰  0) (hβ‚‚ : c β‰  1) (h₃ : c β‰  -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ© #align real.div_logb Real.div_logb section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b β‰  1) private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0; linarith
have b_ne_minus_one : b β‰  -1
private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0; linarith
Mathlib.Analysis.SpecialFunctions.Log.Base.120_0.egNyp4fdqSCAE7f
private theorem log_b_ne_zero : log b β‰  0
Mathlib_Analysis_SpecialFunctions_Log_Base
case b_ne_minus_one b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 b_ne_zero : b β‰  0 ⊒ b β‰  -1 b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 b_ne_zero : b β‰  0 b_ne_minus_one : b β‰  -1 ⊒ log b β‰  0
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel _ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)] #align real.mul_logb Real.mul_logb theorem div_logb {a b c : ℝ} (h₁ : c β‰  0) (hβ‚‚ : c β‰  1) (h₃ : c β‰  -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ© #align real.div_logb Real.div_logb section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b β‰  1) private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0; linarith have b_ne_minus_one : b β‰  -1;
linarith
private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0; linarith have b_ne_minus_one : b β‰  -1;
Mathlib.Analysis.SpecialFunctions.Log.Base.120_0.egNyp4fdqSCAE7f
private theorem log_b_ne_zero : log b β‰  0
Mathlib_Analysis_SpecialFunctions_Log_Base
b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 b_ne_zero : b β‰  0 b_ne_minus_one : b β‰  -1 ⊒ log b β‰  0
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel _ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)] #align real.mul_logb Real.mul_logb theorem div_logb {a b c : ℝ} (h₁ : c β‰  0) (hβ‚‚ : c β‰  1) (h₃ : c β‰  -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ© #align real.div_logb Real.div_logb section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b β‰  1) private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0; linarith have b_ne_minus_one : b β‰  -1; linarith
simp [b_ne_one, b_ne_zero, b_ne_minus_one]
private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0; linarith have b_ne_minus_one : b β‰  -1; linarith
Mathlib.Analysis.SpecialFunctions.Log.Base.120_0.egNyp4fdqSCAE7f
private theorem log_b_ne_zero : log b β‰  0
Mathlib_Analysis_SpecialFunctions_Log_Base
b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 ⊒ logb b (b ^ x) = x
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel _ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)] #align real.mul_logb Real.mul_logb theorem div_logb {a b c : ℝ} (h₁ : c β‰  0) (hβ‚‚ : c β‰  1) (h₃ : c β‰  -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ© #align real.div_logb Real.div_logb section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b β‰  1) private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0; linarith have b_ne_minus_one : b β‰  -1; linarith simp [b_ne_one, b_ne_zero, b_ne_minus_one] @[simp] theorem logb_rpow : logb b (b ^ x) = x := by
rw [logb, div_eq_iff, log_rpow b_pos]
@[simp] theorem logb_rpow : logb b (b ^ x) = x := by
Mathlib.Analysis.SpecialFunctions.Log.Base.125_0.egNyp4fdqSCAE7f
@[simp] theorem logb_rpow : logb b (b ^ x) = x
Mathlib_Analysis_SpecialFunctions_Log_Base
b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 ⊒ log b β‰  0
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel _ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)] #align real.mul_logb Real.mul_logb theorem div_logb {a b c : ℝ} (h₁ : c β‰  0) (hβ‚‚ : c β‰  1) (h₃ : c β‰  -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ© #align real.div_logb Real.div_logb section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b β‰  1) private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0; linarith have b_ne_minus_one : b β‰  -1; linarith simp [b_ne_one, b_ne_zero, b_ne_minus_one] @[simp] theorem logb_rpow : logb b (b ^ x) = x := by rw [logb, div_eq_iff, log_rpow b_pos]
exact log_b_ne_zero b_pos b_ne_one
@[simp] theorem logb_rpow : logb b (b ^ x) = x := by rw [logb, div_eq_iff, log_rpow b_pos]
Mathlib.Analysis.SpecialFunctions.Log.Base.125_0.egNyp4fdqSCAE7f
@[simp] theorem logb_rpow : logb b (b ^ x) = x
Mathlib_Analysis_SpecialFunctions_Log_Base
b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 hx : x β‰  0 ⊒ b ^ logb b x = |x|
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel _ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)] #align real.mul_logb Real.mul_logb theorem div_logb {a b c : ℝ} (h₁ : c β‰  0) (hβ‚‚ : c β‰  1) (h₃ : c β‰  -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ© #align real.div_logb Real.div_logb section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b β‰  1) private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0; linarith have b_ne_minus_one : b β‰  -1; linarith simp [b_ne_one, b_ne_zero, b_ne_minus_one] @[simp] theorem logb_rpow : logb b (b ^ x) = x := by rw [logb, div_eq_iff, log_rpow b_pos] exact log_b_ne_zero b_pos b_ne_one #align real.logb_rpow Real.logb_rpow theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x| := by
apply log_injOn_pos
theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x| := by
Mathlib.Analysis.SpecialFunctions.Log.Base.131_0.egNyp4fdqSCAE7f
theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x|
Mathlib_Analysis_SpecialFunctions_Log_Base
case a b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 hx : x β‰  0 ⊒ b ^ logb b x ∈ Ioi 0 case a b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 hx : x β‰  0 ⊒ |x| ∈ Ioi 0 case a b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 hx : x β‰  0 ⊒ log (b ^ logb b x) = log |x|
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel _ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)] #align real.mul_logb Real.mul_logb theorem div_logb {a b c : ℝ} (h₁ : c β‰  0) (hβ‚‚ : c β‰  1) (h₃ : c β‰  -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ© #align real.div_logb Real.div_logb section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b β‰  1) private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0; linarith have b_ne_minus_one : b β‰  -1; linarith simp [b_ne_one, b_ne_zero, b_ne_minus_one] @[simp] theorem logb_rpow : logb b (b ^ x) = x := by rw [logb, div_eq_iff, log_rpow b_pos] exact log_b_ne_zero b_pos b_ne_one #align real.logb_rpow Real.logb_rpow theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x| := by apply log_injOn_pos
simp only [Set.mem_Ioi]
theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x| := by apply log_injOn_pos
Mathlib.Analysis.SpecialFunctions.Log.Base.131_0.egNyp4fdqSCAE7f
theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x|
Mathlib_Analysis_SpecialFunctions_Log_Base
case a b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 hx : x β‰  0 ⊒ 0 < b ^ logb b x case a b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 hx : x β‰  0 ⊒ |x| ∈ Ioi 0 case a b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 hx : x β‰  0 ⊒ log (b ^ logb b x) = log |x|
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel _ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)] #align real.mul_logb Real.mul_logb theorem div_logb {a b c : ℝ} (h₁ : c β‰  0) (hβ‚‚ : c β‰  1) (h₃ : c β‰  -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ© #align real.div_logb Real.div_logb section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b β‰  1) private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0; linarith have b_ne_minus_one : b β‰  -1; linarith simp [b_ne_one, b_ne_zero, b_ne_minus_one] @[simp] theorem logb_rpow : logb b (b ^ x) = x := by rw [logb, div_eq_iff, log_rpow b_pos] exact log_b_ne_zero b_pos b_ne_one #align real.logb_rpow Real.logb_rpow theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x| := by apply log_injOn_pos simp only [Set.mem_Ioi]
apply rpow_pos_of_pos b_pos
theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x| := by apply log_injOn_pos simp only [Set.mem_Ioi]
Mathlib.Analysis.SpecialFunctions.Log.Base.131_0.egNyp4fdqSCAE7f
theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x|
Mathlib_Analysis_SpecialFunctions_Log_Base
case a b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 hx : x β‰  0 ⊒ |x| ∈ Ioi 0 case a b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 hx : x β‰  0 ⊒ log (b ^ logb b x) = log |x|
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel _ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)] #align real.mul_logb Real.mul_logb theorem div_logb {a b c : ℝ} (h₁ : c β‰  0) (hβ‚‚ : c β‰  1) (h₃ : c β‰  -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ© #align real.div_logb Real.div_logb section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b β‰  1) private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0; linarith have b_ne_minus_one : b β‰  -1; linarith simp [b_ne_one, b_ne_zero, b_ne_minus_one] @[simp] theorem logb_rpow : logb b (b ^ x) = x := by rw [logb, div_eq_iff, log_rpow b_pos] exact log_b_ne_zero b_pos b_ne_one #align real.logb_rpow Real.logb_rpow theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x| := by apply log_injOn_pos simp only [Set.mem_Ioi] apply rpow_pos_of_pos b_pos
simp only [abs_pos, mem_Ioi, Ne.def, hx, not_false_iff]
theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x| := by apply log_injOn_pos simp only [Set.mem_Ioi] apply rpow_pos_of_pos b_pos
Mathlib.Analysis.SpecialFunctions.Log.Base.131_0.egNyp4fdqSCAE7f
theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x|
Mathlib_Analysis_SpecialFunctions_Log_Base
case a b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 hx : x β‰  0 ⊒ log (b ^ logb b x) = log |x|
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel _ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)] #align real.mul_logb Real.mul_logb theorem div_logb {a b c : ℝ} (h₁ : c β‰  0) (hβ‚‚ : c β‰  1) (h₃ : c β‰  -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ© #align real.div_logb Real.div_logb section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b β‰  1) private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0; linarith have b_ne_minus_one : b β‰  -1; linarith simp [b_ne_one, b_ne_zero, b_ne_minus_one] @[simp] theorem logb_rpow : logb b (b ^ x) = x := by rw [logb, div_eq_iff, log_rpow b_pos] exact log_b_ne_zero b_pos b_ne_one #align real.logb_rpow Real.logb_rpow theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x| := by apply log_injOn_pos simp only [Set.mem_Ioi] apply rpow_pos_of_pos b_pos simp only [abs_pos, mem_Ioi, Ne.def, hx, not_false_iff]
rw [log_rpow b_pos, logb, log_abs]
theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x| := by apply log_injOn_pos simp only [Set.mem_Ioi] apply rpow_pos_of_pos b_pos simp only [abs_pos, mem_Ioi, Ne.def, hx, not_false_iff]
Mathlib.Analysis.SpecialFunctions.Log.Base.131_0.egNyp4fdqSCAE7f
theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x|
Mathlib_Analysis_SpecialFunctions_Log_Base
case a b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 hx : x β‰  0 ⊒ log x / log b * log b = log x
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel _ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)] #align real.mul_logb Real.mul_logb theorem div_logb {a b c : ℝ} (h₁ : c β‰  0) (hβ‚‚ : c β‰  1) (h₃ : c β‰  -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ© #align real.div_logb Real.div_logb section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b β‰  1) private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0; linarith have b_ne_minus_one : b β‰  -1; linarith simp [b_ne_one, b_ne_zero, b_ne_minus_one] @[simp] theorem logb_rpow : logb b (b ^ x) = x := by rw [logb, div_eq_iff, log_rpow b_pos] exact log_b_ne_zero b_pos b_ne_one #align real.logb_rpow Real.logb_rpow theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x| := by apply log_injOn_pos simp only [Set.mem_Ioi] apply rpow_pos_of_pos b_pos simp only [abs_pos, mem_Ioi, Ne.def, hx, not_false_iff] rw [log_rpow b_pos, logb, log_abs]
field_simp [log_b_ne_zero b_pos b_ne_one]
theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x| := by apply log_injOn_pos simp only [Set.mem_Ioi] apply rpow_pos_of_pos b_pos simp only [abs_pos, mem_Ioi, Ne.def, hx, not_false_iff] rw [log_rpow b_pos, logb, log_abs]
Mathlib.Analysis.SpecialFunctions.Log.Base.131_0.egNyp4fdqSCAE7f
theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x|
Mathlib_Analysis_SpecialFunctions_Log_Base
b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 hx : 0 < x ⊒ b ^ logb b x = x
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel _ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)] #align real.mul_logb Real.mul_logb theorem div_logb {a b c : ℝ} (h₁ : c β‰  0) (hβ‚‚ : c β‰  1) (h₃ : c β‰  -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ© #align real.div_logb Real.div_logb section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b β‰  1) private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0; linarith have b_ne_minus_one : b β‰  -1; linarith simp [b_ne_one, b_ne_zero, b_ne_minus_one] @[simp] theorem logb_rpow : logb b (b ^ x) = x := by rw [logb, div_eq_iff, log_rpow b_pos] exact log_b_ne_zero b_pos b_ne_one #align real.logb_rpow Real.logb_rpow theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x| := by apply log_injOn_pos simp only [Set.mem_Ioi] apply rpow_pos_of_pos b_pos simp only [abs_pos, mem_Ioi, Ne.def, hx, not_false_iff] rw [log_rpow b_pos, logb, log_abs] field_simp [log_b_ne_zero b_pos b_ne_one] #align real.rpow_logb_eq_abs Real.rpow_logb_eq_abs @[simp] theorem rpow_logb (hx : 0 < x) : b ^ logb b x = x := by
rw [rpow_logb_eq_abs b_pos b_ne_one hx.ne']
@[simp] theorem rpow_logb (hx : 0 < x) : b ^ logb b x = x := by
Mathlib.Analysis.SpecialFunctions.Log.Base.140_0.egNyp4fdqSCAE7f
@[simp] theorem rpow_logb (hx : 0 < x) : b ^ logb b x = x
Mathlib_Analysis_SpecialFunctions_Log_Base
b x y : ℝ b_pos : 0 < b b_ne_one : b β‰  1 hx : 0 < x ⊒ |x| = x
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel _ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)] #align real.mul_logb Real.mul_logb theorem div_logb {a b c : ℝ} (h₁ : c β‰  0) (hβ‚‚ : c β‰  1) (h₃ : c β‰  -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ© #align real.div_logb Real.div_logb section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b β‰  1) private theorem log_b_ne_zero : log b β‰  0 := by have b_ne_zero : b β‰  0; linarith have b_ne_minus_one : b β‰  -1; linarith simp [b_ne_one, b_ne_zero, b_ne_minus_one] @[simp] theorem logb_rpow : logb b (b ^ x) = x := by rw [logb, div_eq_iff, log_rpow b_pos] exact log_b_ne_zero b_pos b_ne_one #align real.logb_rpow Real.logb_rpow theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x| := by apply log_injOn_pos simp only [Set.mem_Ioi] apply rpow_pos_of_pos b_pos simp only [abs_pos, mem_Ioi, Ne.def, hx, not_false_iff] rw [log_rpow b_pos, logb, log_abs] field_simp [log_b_ne_zero b_pos b_ne_one] #align real.rpow_logb_eq_abs Real.rpow_logb_eq_abs @[simp] theorem rpow_logb (hx : 0 < x) : b ^ logb b x = x := by rw [rpow_logb_eq_abs b_pos b_ne_one hx.ne']
exact abs_of_pos hx
@[simp] theorem rpow_logb (hx : 0 < x) : b ^ logb b x = x := by rw [rpow_logb_eq_abs b_pos b_ne_one hx.ne']
Mathlib.Analysis.SpecialFunctions.Log.Base.140_0.egNyp4fdqSCAE7f
@[simp] theorem rpow_logb (hx : 0 < x) : b ^ logb b x = x
Mathlib_Analysis_SpecialFunctions_Log_Base