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 mk.intro.intro.mk.intro.intro
R : Type u_1
π : Type u_2
B : Type u_3
F : Type u_4
E : B β Type u_5
B' : Type u_6
fβ : B' β B
instβΒΉΒΉ : TopologicalSpace B'
instβΒΉβ° : TopologicalSpace (TotalSpace F E)
instββΉ : NontriviallyNormedField π
instββΈ : NormedAddCommGroup F
instββ· : NormedSpace π F
instββΆ : TopologicalSpace B
instββ΅ : (x : B) β AddCommMonoid (E x)
instββ΄ : (x : B) β Module π (E x)
K : Type u_7
instβΒ³ : ContinuousMapClass K B' B
instβΒ² : (x : B) β TopologicalSpace (E x)
instβΒΉ : FiberBundle F E
instβ : VectorBundle π F E
f : K
e : Trivialization F TotalSpace.proj
he : MemTrivializationAtlas e
e' : Trivialization F TotalSpace.proj
he' : MemTrivializationAtlas e'
b : B'
hb : f b β e.baseSet β© e'.baseSet
β’ (fun b => β(Trivialization.coordChangeL π (Trivialization.pullback e f) (Trivialization.pullback e' f) b)) b =
((fun b => β(Trivialization.coordChangeL π e e' b)) β βf) b | /-
Copyright Β© 2022 NicolΓ² Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: NicolΓ² Cavalleri, SΓ©bastien GouΓ«zel, Heather Macbeth, Floris van Doorn
-/
import Mathlib.Topology.FiberBundle.Constructions
import Mathlib.Topology.VectorBundle.Basic
#align_import topology.vector_bundle.constructions from "leanprover-community/mathlib"@"e473c3198bb41f68560cab68a0529c854b618833"
/-!
# Standard constructions on vector bundles
This file contains several standard constructions on vector bundles:
* `Bundle.Trivial.vectorBundle π B F`: the trivial vector bundle with scalar field `π` and model
fiber `F` over the base `B`
* `VectorBundle.prod`: for vector bundles `Eβ` and `Eβ` with scalar field `π` over a common base,
a vector bundle structure on their direct sum `Eβ Γα΅ Eβ` (the notation stands for
`fun x β¦ Eβ x Γ Eβ x`).
* `VectorBundle.pullback`: for a vector bundle `E` over `B`, a vector bundle structure on its
pullback `f *α΅ E` by a map `f : B' β B` (the notation is a type synonym for `E β f`).
## Tags
Vector bundle, direct sum, pullback
-/
noncomputable section
open Bundle Set FiberBundle Classical
/-! ### The trivial vector bundle -/
namespace Bundle.Trivial
variable (π : Type*) (B : Type*) (F : Type*) [NontriviallyNormedField π] [NormedAddCommGroup F]
[NormedSpace π F] [TopologicalSpace B]
instance trivialization.isLinear : (trivialization B F).IsLinear π where
linear _ _ := β¨fun _ _ => rfl, fun _ _ => rflβ©
#align bundle.trivial.trivialization.is_linear Bundle.Trivial.trivialization.isLinear
variable {π}
theorem trivialization.coordChangeL (b : B) :
(trivialization B F).coordChangeL π (trivialization B F) b =
ContinuousLinearEquiv.refl π F := by
ext v
rw [Trivialization.coordChangeL_apply']
exacts [rfl, β¨mem_univ _, mem_univ _β©]
set_option linter.uppercaseLean3 false in
#align bundle.trivial.trivialization.coord_changeL Bundle.Trivial.trivialization.coordChangeL
variable (π)
instance vectorBundle : VectorBundle π F (Bundle.Trivial B F) where
trivialization_linear' e he := by
rw [eq_trivialization B F e]
infer_instance
continuousOn_coordChange' e e' he he' := by
obtain rfl := eq_trivialization B F e
obtain rfl := eq_trivialization B F e'
simp only [trivialization.coordChangeL]
exact continuous_const.continuousOn
#align bundle.trivial.vector_bundle Bundle.Trivial.vectorBundle
end Bundle.Trivial
/-! ### Direct sum of two vector bundles -/
section
variable (π : Type*) {B : Type*} [NontriviallyNormedField π] [TopologicalSpace B] (Fβ : Type*)
[NormedAddCommGroup Fβ] [NormedSpace π Fβ] (Eβ : B β Type*) [TopologicalSpace (TotalSpace Fβ Eβ)]
(Fβ : Type*) [NormedAddCommGroup Fβ] [NormedSpace π Fβ] (Eβ : B β Type*)
[TopologicalSpace (TotalSpace Fβ Eβ)]
namespace Trivialization
variable {Fβ Eβ Fβ Eβ}
variable [β x, AddCommMonoid (Eβ x)] [β x, Module π (Eβ x)]
[β x, AddCommMonoid (Eβ x)] [β x, Module π (Eβ x)] (eβ eβ' : Trivialization Fβ (Ο Fβ Eβ))
(eβ eβ' : Trivialization Fβ (Ο Fβ Eβ))
instance prod.isLinear [eβ.IsLinear π] [eβ.IsLinear π] : (eβ.prod eβ).IsLinear π where
linear := fun _ β¨hβ, hββ© =>
(((eβ.linear π hβ).mk' _).prodMap ((eβ.linear π hβ).mk' _)).isLinear
#align trivialization.prod.is_linear Trivialization.prod.isLinear
@[simp]
theorem coordChangeL_prod [eβ.IsLinear π] [eβ'.IsLinear π] [eβ.IsLinear π] [eβ'.IsLinear π] β¦bβ¦
(hb : b β (eβ.prod eβ).baseSet β© (eβ'.prod eβ').baseSet) :
((eβ.prod eβ).coordChangeL π (eβ'.prod eβ') b : Fβ Γ Fβ βL[π] Fβ Γ Fβ) =
(eβ.coordChangeL π eβ' b : Fβ βL[π] Fβ).prodMap (eβ.coordChangeL π eβ' b) := by
rw [ContinuousLinearMap.ext_iff, ContinuousLinearMap.coe_prodMap']
rintro β¨vβ, vββ©
show
(eβ.prod eβ).coordChangeL π (eβ'.prod eβ') b (vβ, vβ) =
(eβ.coordChangeL π eβ' b vβ, eβ.coordChangeL π eβ' b vβ)
rw [eβ.coordChangeL_apply eβ', eβ.coordChangeL_apply eβ', (eβ.prod eβ).coordChangeL_apply']
exacts [rfl, hb, β¨hb.1.2, hb.2.2β©, β¨hb.1.1, hb.2.1β©]
set_option linter.uppercaseLean3 false in
#align trivialization.coord_changeL_prod Trivialization.coordChangeL_prod
variable {eβ eβ} [β x : B, TopologicalSpace (Eβ x)] [β x : B, TopologicalSpace (Eβ x)]
[FiberBundle Fβ Eβ] [FiberBundle Fβ Eβ]
theorem prod_apply [eβ.IsLinear π] [eβ.IsLinear π] {x : B} (hxβ : x β eβ.baseSet)
(hxβ : x β eβ.baseSet) (vβ : Eβ x) (vβ : Eβ x) :
prod eβ eβ β¨x, (vβ, vβ)β© =
β¨x, eβ.continuousLinearEquivAt π x hxβ vβ, eβ.continuousLinearEquivAt π x hxβ vββ© :=
rfl
#align trivialization.prod_apply Trivialization.prod_apply
end Trivialization
open Trivialization
variable [β x, AddCommMonoid (Eβ x)] [β x, Module π (Eβ x)] [β x, AddCommMonoid (Eβ x)]
[β x, Module π (Eβ x)] [β x : B, TopologicalSpace (Eβ x)] [β x : B, TopologicalSpace (Eβ x)]
[FiberBundle Fβ Eβ] [FiberBundle Fβ Eβ]
/-- The product of two vector bundles is a vector bundle. -/
instance VectorBundle.prod [VectorBundle π Fβ Eβ] [VectorBundle π Fβ Eβ] :
VectorBundle π (Fβ Γ Fβ) (Eβ Γα΅ Eβ) where
trivialization_linear' := by
rintro _ β¨eβ, eβ, heβ, heβ, rflβ©; skip
infer_instance
continuousOn_coordChange' := by
rintro _ _ β¨eβ, eβ, heβ, heβ, rflβ© β¨eβ', eβ', heβ', heβ', rflβ©; skip
refine' (((continuousOn_coordChange π eβ eβ').mono _).prod_mapL π
((continuousOn_coordChange π eβ eβ').mono _)).congr _ <;>
dsimp only [baseSet_prod, mfld_simps]
Β· mfld_set_tac
Β· mfld_set_tac
Β· rintro b hb
rw [ContinuousLinearMap.ext_iff]
rintro β¨vβ, vββ©
show (eβ.prod eβ).coordChangeL π (eβ'.prod eβ') b (vβ, vβ) =
(eβ.coordChangeL π eβ' b vβ, eβ.coordChangeL π eβ' b vβ)
rw [eβ.coordChangeL_apply eβ', eβ.coordChangeL_apply eβ', (eβ.prod eβ).coordChangeL_apply']
exacts [rfl, hb, β¨hb.1.2, hb.2.2β©, β¨hb.1.1, hb.2.1β©]
#align vector_bundle.prod VectorBundle.prod
variable {π Fβ Eβ Fβ Eβ}
@[simp] -- porting note: changed arguments to make `simpNF` happy: merged `hxβ` and `hxβ` into `hx`
theorem Trivialization.continuousLinearEquivAt_prod {eβ : Trivialization Fβ (Ο Fβ Eβ)}
{eβ : Trivialization Fβ (Ο Fβ Eβ)} [eβ.IsLinear π] [eβ.IsLinear π] {x : B}
(hx : x β (eβ.prod eβ).baseSet) :
(eβ.prod eβ).continuousLinearEquivAt π x hx =
(eβ.continuousLinearEquivAt π x hx.1).prod (eβ.continuousLinearEquivAt π x hx.2) := by
ext v : 2
obtain β¨vβ, vββ© := v
rw [(eβ.prod eβ).continuousLinearEquivAt_apply π, Trivialization.prod]
exact (congr_arg Prod.snd (prod_apply π hx.1 hx.2 vβ vβ) : _)
#align trivialization.continuous_linear_equiv_at_prod Trivialization.continuousLinearEquivAt_prodβ
end
/-! ### Pullbacks of vector bundles -/
section
variable (R π : Type*) {B : Type*} (F : Type*) (E : B β Type*) {B' : Type*} (f : B' β B)
instance [i : β x : B, AddCommMonoid (E x)] (x : B') : AddCommMonoid ((f *α΅ E) x) := i _
instance [Semiring R] [β x : B, AddCommMonoid (E x)] [i : β x, Module R (E x)] (x : B') :
Module R ((f *α΅ E) x) := i _
variable {E F} [TopologicalSpace B'] [TopologicalSpace (TotalSpace F E)] [NontriviallyNormedField π]
[NormedAddCommGroup F] [NormedSpace π F] [TopologicalSpace B] [β x, AddCommMonoid (E x)]
[β x, Module π (E x)] {K : Type*} [ContinuousMapClass K B' B]
instance Trivialization.pullback_linear (e : Trivialization F (Ο F E)) [e.IsLinear π] (f : K) :
(@Trivialization.pullback _ _ _ B' _ _ _ _ _ _ _ e f).IsLinear π where
linear _ h := e.linear π h
#align trivialization.pullback_linear Trivialization.pullback_linear
instance VectorBundle.pullback [β x, TopologicalSpace (E x)] [FiberBundle F E] [VectorBundle π F E]
(f : K) : VectorBundle π F ((f : B' β B) *α΅ E) where
trivialization_linear' := by
rintro _ β¨e, he, rflβ©
infer_instance
continuousOn_coordChange' := by
rintro _ _ β¨e, he, rflβ© β¨e', he', rflβ©
refine' ((continuousOn_coordChange π e e').comp
(map_continuous f).continuousOn fun b hb => hb).congr _
rintro b (hb : f b β e.baseSet β© e'.baseSet); | ext v | instance VectorBundle.pullback [β x, TopologicalSpace (E x)] [FiberBundle F E] [VectorBundle π F E]
(f : K) : VectorBundle π F ((f : B' β B) *α΅ E) where
trivialization_linear' := by
rintro _ β¨e, he, rflβ©
infer_instance
continuousOn_coordChange' := by
rintro _ _ β¨e, he, rflβ© β¨e', he', rflβ©
refine' ((continuousOn_coordChange π e e').comp
(map_continuous f).continuousOn fun b hb => hb).congr _
rintro b (hb : f b β e.baseSet β© e'.baseSet); | Mathlib.Topology.VectorBundle.Constructions.184_0.ZrgS90NPsSlDzPQ | instance VectorBundle.pullback [β x, TopologicalSpace (E x)] [FiberBundle F E] [VectorBundle π F E]
(f : K) : VectorBundle π F ((f : B' β B) *α΅ E) where
trivialization_linear' | Mathlib_Topology_VectorBundle_Constructions |
case mk.intro.intro.mk.intro.intro.h
R : Type u_1
π : Type u_2
B : Type u_3
F : Type u_4
E : B β Type u_5
B' : Type u_6
fβ : B' β B
instβΒΉΒΉ : TopologicalSpace B'
instβΒΉβ° : TopologicalSpace (TotalSpace F E)
instββΉ : NontriviallyNormedField π
instββΈ : NormedAddCommGroup F
instββ· : NormedSpace π F
instββΆ : TopologicalSpace B
instββ΅ : (x : B) β AddCommMonoid (E x)
instββ΄ : (x : B) β Module π (E x)
K : Type u_7
instβΒ³ : ContinuousMapClass K B' B
instβΒ² : (x : B) β TopologicalSpace (E x)
instβΒΉ : FiberBundle F E
instβ : VectorBundle π F E
f : K
e : Trivialization F TotalSpace.proj
he : MemTrivializationAtlas e
e' : Trivialization F TotalSpace.proj
he' : MemTrivializationAtlas e'
b : B'
hb : f b β e.baseSet β© e'.baseSet
v : F
β’ ((fun b => β(Trivialization.coordChangeL π (Trivialization.pullback e f) (Trivialization.pullback e' f) b)) b) v =
(((fun b => β(Trivialization.coordChangeL π e e' b)) β βf) b) v | /-
Copyright Β© 2022 NicolΓ² Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: NicolΓ² Cavalleri, SΓ©bastien GouΓ«zel, Heather Macbeth, Floris van Doorn
-/
import Mathlib.Topology.FiberBundle.Constructions
import Mathlib.Topology.VectorBundle.Basic
#align_import topology.vector_bundle.constructions from "leanprover-community/mathlib"@"e473c3198bb41f68560cab68a0529c854b618833"
/-!
# Standard constructions on vector bundles
This file contains several standard constructions on vector bundles:
* `Bundle.Trivial.vectorBundle π B F`: the trivial vector bundle with scalar field `π` and model
fiber `F` over the base `B`
* `VectorBundle.prod`: for vector bundles `Eβ` and `Eβ` with scalar field `π` over a common base,
a vector bundle structure on their direct sum `Eβ Γα΅ Eβ` (the notation stands for
`fun x β¦ Eβ x Γ Eβ x`).
* `VectorBundle.pullback`: for a vector bundle `E` over `B`, a vector bundle structure on its
pullback `f *α΅ E` by a map `f : B' β B` (the notation is a type synonym for `E β f`).
## Tags
Vector bundle, direct sum, pullback
-/
noncomputable section
open Bundle Set FiberBundle Classical
/-! ### The trivial vector bundle -/
namespace Bundle.Trivial
variable (π : Type*) (B : Type*) (F : Type*) [NontriviallyNormedField π] [NormedAddCommGroup F]
[NormedSpace π F] [TopologicalSpace B]
instance trivialization.isLinear : (trivialization B F).IsLinear π where
linear _ _ := β¨fun _ _ => rfl, fun _ _ => rflβ©
#align bundle.trivial.trivialization.is_linear Bundle.Trivial.trivialization.isLinear
variable {π}
theorem trivialization.coordChangeL (b : B) :
(trivialization B F).coordChangeL π (trivialization B F) b =
ContinuousLinearEquiv.refl π F := by
ext v
rw [Trivialization.coordChangeL_apply']
exacts [rfl, β¨mem_univ _, mem_univ _β©]
set_option linter.uppercaseLean3 false in
#align bundle.trivial.trivialization.coord_changeL Bundle.Trivial.trivialization.coordChangeL
variable (π)
instance vectorBundle : VectorBundle π F (Bundle.Trivial B F) where
trivialization_linear' e he := by
rw [eq_trivialization B F e]
infer_instance
continuousOn_coordChange' e e' he he' := by
obtain rfl := eq_trivialization B F e
obtain rfl := eq_trivialization B F e'
simp only [trivialization.coordChangeL]
exact continuous_const.continuousOn
#align bundle.trivial.vector_bundle Bundle.Trivial.vectorBundle
end Bundle.Trivial
/-! ### Direct sum of two vector bundles -/
section
variable (π : Type*) {B : Type*} [NontriviallyNormedField π] [TopologicalSpace B] (Fβ : Type*)
[NormedAddCommGroup Fβ] [NormedSpace π Fβ] (Eβ : B β Type*) [TopologicalSpace (TotalSpace Fβ Eβ)]
(Fβ : Type*) [NormedAddCommGroup Fβ] [NormedSpace π Fβ] (Eβ : B β Type*)
[TopologicalSpace (TotalSpace Fβ Eβ)]
namespace Trivialization
variable {Fβ Eβ Fβ Eβ}
variable [β x, AddCommMonoid (Eβ x)] [β x, Module π (Eβ x)]
[β x, AddCommMonoid (Eβ x)] [β x, Module π (Eβ x)] (eβ eβ' : Trivialization Fβ (Ο Fβ Eβ))
(eβ eβ' : Trivialization Fβ (Ο Fβ Eβ))
instance prod.isLinear [eβ.IsLinear π] [eβ.IsLinear π] : (eβ.prod eβ).IsLinear π where
linear := fun _ β¨hβ, hββ© =>
(((eβ.linear π hβ).mk' _).prodMap ((eβ.linear π hβ).mk' _)).isLinear
#align trivialization.prod.is_linear Trivialization.prod.isLinear
@[simp]
theorem coordChangeL_prod [eβ.IsLinear π] [eβ'.IsLinear π] [eβ.IsLinear π] [eβ'.IsLinear π] β¦bβ¦
(hb : b β (eβ.prod eβ).baseSet β© (eβ'.prod eβ').baseSet) :
((eβ.prod eβ).coordChangeL π (eβ'.prod eβ') b : Fβ Γ Fβ βL[π] Fβ Γ Fβ) =
(eβ.coordChangeL π eβ' b : Fβ βL[π] Fβ).prodMap (eβ.coordChangeL π eβ' b) := by
rw [ContinuousLinearMap.ext_iff, ContinuousLinearMap.coe_prodMap']
rintro β¨vβ, vββ©
show
(eβ.prod eβ).coordChangeL π (eβ'.prod eβ') b (vβ, vβ) =
(eβ.coordChangeL π eβ' b vβ, eβ.coordChangeL π eβ' b vβ)
rw [eβ.coordChangeL_apply eβ', eβ.coordChangeL_apply eβ', (eβ.prod eβ).coordChangeL_apply']
exacts [rfl, hb, β¨hb.1.2, hb.2.2β©, β¨hb.1.1, hb.2.1β©]
set_option linter.uppercaseLean3 false in
#align trivialization.coord_changeL_prod Trivialization.coordChangeL_prod
variable {eβ eβ} [β x : B, TopologicalSpace (Eβ x)] [β x : B, TopologicalSpace (Eβ x)]
[FiberBundle Fβ Eβ] [FiberBundle Fβ Eβ]
theorem prod_apply [eβ.IsLinear π] [eβ.IsLinear π] {x : B} (hxβ : x β eβ.baseSet)
(hxβ : x β eβ.baseSet) (vβ : Eβ x) (vβ : Eβ x) :
prod eβ eβ β¨x, (vβ, vβ)β© =
β¨x, eβ.continuousLinearEquivAt π x hxβ vβ, eβ.continuousLinearEquivAt π x hxβ vββ© :=
rfl
#align trivialization.prod_apply Trivialization.prod_apply
end Trivialization
open Trivialization
variable [β x, AddCommMonoid (Eβ x)] [β x, Module π (Eβ x)] [β x, AddCommMonoid (Eβ x)]
[β x, Module π (Eβ x)] [β x : B, TopologicalSpace (Eβ x)] [β x : B, TopologicalSpace (Eβ x)]
[FiberBundle Fβ Eβ] [FiberBundle Fβ Eβ]
/-- The product of two vector bundles is a vector bundle. -/
instance VectorBundle.prod [VectorBundle π Fβ Eβ] [VectorBundle π Fβ Eβ] :
VectorBundle π (Fβ Γ Fβ) (Eβ Γα΅ Eβ) where
trivialization_linear' := by
rintro _ β¨eβ, eβ, heβ, heβ, rflβ©; skip
infer_instance
continuousOn_coordChange' := by
rintro _ _ β¨eβ, eβ, heβ, heβ, rflβ© β¨eβ', eβ', heβ', heβ', rflβ©; skip
refine' (((continuousOn_coordChange π eβ eβ').mono _).prod_mapL π
((continuousOn_coordChange π eβ eβ').mono _)).congr _ <;>
dsimp only [baseSet_prod, mfld_simps]
Β· mfld_set_tac
Β· mfld_set_tac
Β· rintro b hb
rw [ContinuousLinearMap.ext_iff]
rintro β¨vβ, vββ©
show (eβ.prod eβ).coordChangeL π (eβ'.prod eβ') b (vβ, vβ) =
(eβ.coordChangeL π eβ' b vβ, eβ.coordChangeL π eβ' b vβ)
rw [eβ.coordChangeL_apply eβ', eβ.coordChangeL_apply eβ', (eβ.prod eβ).coordChangeL_apply']
exacts [rfl, hb, β¨hb.1.2, hb.2.2β©, β¨hb.1.1, hb.2.1β©]
#align vector_bundle.prod VectorBundle.prod
variable {π Fβ Eβ Fβ Eβ}
@[simp] -- porting note: changed arguments to make `simpNF` happy: merged `hxβ` and `hxβ` into `hx`
theorem Trivialization.continuousLinearEquivAt_prod {eβ : Trivialization Fβ (Ο Fβ Eβ)}
{eβ : Trivialization Fβ (Ο Fβ Eβ)} [eβ.IsLinear π] [eβ.IsLinear π] {x : B}
(hx : x β (eβ.prod eβ).baseSet) :
(eβ.prod eβ).continuousLinearEquivAt π x hx =
(eβ.continuousLinearEquivAt π x hx.1).prod (eβ.continuousLinearEquivAt π x hx.2) := by
ext v : 2
obtain β¨vβ, vββ© := v
rw [(eβ.prod eβ).continuousLinearEquivAt_apply π, Trivialization.prod]
exact (congr_arg Prod.snd (prod_apply π hx.1 hx.2 vβ vβ) : _)
#align trivialization.continuous_linear_equiv_at_prod Trivialization.continuousLinearEquivAt_prodβ
end
/-! ### Pullbacks of vector bundles -/
section
variable (R π : Type*) {B : Type*} (F : Type*) (E : B β Type*) {B' : Type*} (f : B' β B)
instance [i : β x : B, AddCommMonoid (E x)] (x : B') : AddCommMonoid ((f *α΅ E) x) := i _
instance [Semiring R] [β x : B, AddCommMonoid (E x)] [i : β x, Module R (E x)] (x : B') :
Module R ((f *α΅ E) x) := i _
variable {E F} [TopologicalSpace B'] [TopologicalSpace (TotalSpace F E)] [NontriviallyNormedField π]
[NormedAddCommGroup F] [NormedSpace π F] [TopologicalSpace B] [β x, AddCommMonoid (E x)]
[β x, Module π (E x)] {K : Type*} [ContinuousMapClass K B' B]
instance Trivialization.pullback_linear (e : Trivialization F (Ο F E)) [e.IsLinear π] (f : K) :
(@Trivialization.pullback _ _ _ B' _ _ _ _ _ _ _ e f).IsLinear π where
linear _ h := e.linear π h
#align trivialization.pullback_linear Trivialization.pullback_linear
instance VectorBundle.pullback [β x, TopologicalSpace (E x)] [FiberBundle F E] [VectorBundle π F E]
(f : K) : VectorBundle π F ((f : B' β B) *α΅ E) where
trivialization_linear' := by
rintro _ β¨e, he, rflβ©
infer_instance
continuousOn_coordChange' := by
rintro _ _ β¨e, he, rflβ© β¨e', he', rflβ©
refine' ((continuousOn_coordChange π e e').comp
(map_continuous f).continuousOn fun b hb => hb).congr _
rintro b (hb : f b β e.baseSet β© e'.baseSet); ext v
| show ((e.pullback f).coordChangeL π (e'.pullback f) b) v = (e.coordChangeL π e' (f b)) v | instance VectorBundle.pullback [β x, TopologicalSpace (E x)] [FiberBundle F E] [VectorBundle π F E]
(f : K) : VectorBundle π F ((f : B' β B) *α΅ E) where
trivialization_linear' := by
rintro _ β¨e, he, rflβ©
infer_instance
continuousOn_coordChange' := by
rintro _ _ β¨e, he, rflβ© β¨e', he', rflβ©
refine' ((continuousOn_coordChange π e e').comp
(map_continuous f).continuousOn fun b hb => hb).congr _
rintro b (hb : f b β e.baseSet β© e'.baseSet); ext v
| Mathlib.Topology.VectorBundle.Constructions.184_0.ZrgS90NPsSlDzPQ | instance VectorBundle.pullback [β x, TopologicalSpace (E x)] [FiberBundle F E] [VectorBundle π F E]
(f : K) : VectorBundle π F ((f : B' β B) *α΅ E) where
trivialization_linear' | Mathlib_Topology_VectorBundle_Constructions |
case mk.intro.intro.mk.intro.intro.h
R : Type u_1
π : Type u_2
B : Type u_3
F : Type u_4
E : B β Type u_5
B' : Type u_6
fβ : B' β B
instβΒΉΒΉ : TopologicalSpace B'
instβΒΉβ° : TopologicalSpace (TotalSpace F E)
instββΉ : NontriviallyNormedField π
instββΈ : NormedAddCommGroup F
instββ· : NormedSpace π F
instββΆ : TopologicalSpace B
instββ΅ : (x : B) β AddCommMonoid (E x)
instββ΄ : (x : B) β Module π (E x)
K : Type u_7
instβΒ³ : ContinuousMapClass K B' B
instβΒ² : (x : B) β TopologicalSpace (E x)
instβΒΉ : FiberBundle F E
instβ : VectorBundle π F E
f : K
e : Trivialization F TotalSpace.proj
he : MemTrivializationAtlas e
e' : Trivialization F TotalSpace.proj
he' : MemTrivializationAtlas e'
b : B'
hb : f b β e.baseSet β© e'.baseSet
v : F
β’ (Trivialization.coordChangeL π (Trivialization.pullback e f) (Trivialization.pullback e' f) b) v =
(Trivialization.coordChangeL π e e' (f b)) v | /-
Copyright Β© 2022 NicolΓ² Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: NicolΓ² Cavalleri, SΓ©bastien GouΓ«zel, Heather Macbeth, Floris van Doorn
-/
import Mathlib.Topology.FiberBundle.Constructions
import Mathlib.Topology.VectorBundle.Basic
#align_import topology.vector_bundle.constructions from "leanprover-community/mathlib"@"e473c3198bb41f68560cab68a0529c854b618833"
/-!
# Standard constructions on vector bundles
This file contains several standard constructions on vector bundles:
* `Bundle.Trivial.vectorBundle π B F`: the trivial vector bundle with scalar field `π` and model
fiber `F` over the base `B`
* `VectorBundle.prod`: for vector bundles `Eβ` and `Eβ` with scalar field `π` over a common base,
a vector bundle structure on their direct sum `Eβ Γα΅ Eβ` (the notation stands for
`fun x β¦ Eβ x Γ Eβ x`).
* `VectorBundle.pullback`: for a vector bundle `E` over `B`, a vector bundle structure on its
pullback `f *α΅ E` by a map `f : B' β B` (the notation is a type synonym for `E β f`).
## Tags
Vector bundle, direct sum, pullback
-/
noncomputable section
open Bundle Set FiberBundle Classical
/-! ### The trivial vector bundle -/
namespace Bundle.Trivial
variable (π : Type*) (B : Type*) (F : Type*) [NontriviallyNormedField π] [NormedAddCommGroup F]
[NormedSpace π F] [TopologicalSpace B]
instance trivialization.isLinear : (trivialization B F).IsLinear π where
linear _ _ := β¨fun _ _ => rfl, fun _ _ => rflβ©
#align bundle.trivial.trivialization.is_linear Bundle.Trivial.trivialization.isLinear
variable {π}
theorem trivialization.coordChangeL (b : B) :
(trivialization B F).coordChangeL π (trivialization B F) b =
ContinuousLinearEquiv.refl π F := by
ext v
rw [Trivialization.coordChangeL_apply']
exacts [rfl, β¨mem_univ _, mem_univ _β©]
set_option linter.uppercaseLean3 false in
#align bundle.trivial.trivialization.coord_changeL Bundle.Trivial.trivialization.coordChangeL
variable (π)
instance vectorBundle : VectorBundle π F (Bundle.Trivial B F) where
trivialization_linear' e he := by
rw [eq_trivialization B F e]
infer_instance
continuousOn_coordChange' e e' he he' := by
obtain rfl := eq_trivialization B F e
obtain rfl := eq_trivialization B F e'
simp only [trivialization.coordChangeL]
exact continuous_const.continuousOn
#align bundle.trivial.vector_bundle Bundle.Trivial.vectorBundle
end Bundle.Trivial
/-! ### Direct sum of two vector bundles -/
section
variable (π : Type*) {B : Type*} [NontriviallyNormedField π] [TopologicalSpace B] (Fβ : Type*)
[NormedAddCommGroup Fβ] [NormedSpace π Fβ] (Eβ : B β Type*) [TopologicalSpace (TotalSpace Fβ Eβ)]
(Fβ : Type*) [NormedAddCommGroup Fβ] [NormedSpace π Fβ] (Eβ : B β Type*)
[TopologicalSpace (TotalSpace Fβ Eβ)]
namespace Trivialization
variable {Fβ Eβ Fβ Eβ}
variable [β x, AddCommMonoid (Eβ x)] [β x, Module π (Eβ x)]
[β x, AddCommMonoid (Eβ x)] [β x, Module π (Eβ x)] (eβ eβ' : Trivialization Fβ (Ο Fβ Eβ))
(eβ eβ' : Trivialization Fβ (Ο Fβ Eβ))
instance prod.isLinear [eβ.IsLinear π] [eβ.IsLinear π] : (eβ.prod eβ).IsLinear π where
linear := fun _ β¨hβ, hββ© =>
(((eβ.linear π hβ).mk' _).prodMap ((eβ.linear π hβ).mk' _)).isLinear
#align trivialization.prod.is_linear Trivialization.prod.isLinear
@[simp]
theorem coordChangeL_prod [eβ.IsLinear π] [eβ'.IsLinear π] [eβ.IsLinear π] [eβ'.IsLinear π] β¦bβ¦
(hb : b β (eβ.prod eβ).baseSet β© (eβ'.prod eβ').baseSet) :
((eβ.prod eβ).coordChangeL π (eβ'.prod eβ') b : Fβ Γ Fβ βL[π] Fβ Γ Fβ) =
(eβ.coordChangeL π eβ' b : Fβ βL[π] Fβ).prodMap (eβ.coordChangeL π eβ' b) := by
rw [ContinuousLinearMap.ext_iff, ContinuousLinearMap.coe_prodMap']
rintro β¨vβ, vββ©
show
(eβ.prod eβ).coordChangeL π (eβ'.prod eβ') b (vβ, vβ) =
(eβ.coordChangeL π eβ' b vβ, eβ.coordChangeL π eβ' b vβ)
rw [eβ.coordChangeL_apply eβ', eβ.coordChangeL_apply eβ', (eβ.prod eβ).coordChangeL_apply']
exacts [rfl, hb, β¨hb.1.2, hb.2.2β©, β¨hb.1.1, hb.2.1β©]
set_option linter.uppercaseLean3 false in
#align trivialization.coord_changeL_prod Trivialization.coordChangeL_prod
variable {eβ eβ} [β x : B, TopologicalSpace (Eβ x)] [β x : B, TopologicalSpace (Eβ x)]
[FiberBundle Fβ Eβ] [FiberBundle Fβ Eβ]
theorem prod_apply [eβ.IsLinear π] [eβ.IsLinear π] {x : B} (hxβ : x β eβ.baseSet)
(hxβ : x β eβ.baseSet) (vβ : Eβ x) (vβ : Eβ x) :
prod eβ eβ β¨x, (vβ, vβ)β© =
β¨x, eβ.continuousLinearEquivAt π x hxβ vβ, eβ.continuousLinearEquivAt π x hxβ vββ© :=
rfl
#align trivialization.prod_apply Trivialization.prod_apply
end Trivialization
open Trivialization
variable [β x, AddCommMonoid (Eβ x)] [β x, Module π (Eβ x)] [β x, AddCommMonoid (Eβ x)]
[β x, Module π (Eβ x)] [β x : B, TopologicalSpace (Eβ x)] [β x : B, TopologicalSpace (Eβ x)]
[FiberBundle Fβ Eβ] [FiberBundle Fβ Eβ]
/-- The product of two vector bundles is a vector bundle. -/
instance VectorBundle.prod [VectorBundle π Fβ Eβ] [VectorBundle π Fβ Eβ] :
VectorBundle π (Fβ Γ Fβ) (Eβ Γα΅ Eβ) where
trivialization_linear' := by
rintro _ β¨eβ, eβ, heβ, heβ, rflβ©; skip
infer_instance
continuousOn_coordChange' := by
rintro _ _ β¨eβ, eβ, heβ, heβ, rflβ© β¨eβ', eβ', heβ', heβ', rflβ©; skip
refine' (((continuousOn_coordChange π eβ eβ').mono _).prod_mapL π
((continuousOn_coordChange π eβ eβ').mono _)).congr _ <;>
dsimp only [baseSet_prod, mfld_simps]
Β· mfld_set_tac
Β· mfld_set_tac
Β· rintro b hb
rw [ContinuousLinearMap.ext_iff]
rintro β¨vβ, vββ©
show (eβ.prod eβ).coordChangeL π (eβ'.prod eβ') b (vβ, vβ) =
(eβ.coordChangeL π eβ' b vβ, eβ.coordChangeL π eβ' b vβ)
rw [eβ.coordChangeL_apply eβ', eβ.coordChangeL_apply eβ', (eβ.prod eβ).coordChangeL_apply']
exacts [rfl, hb, β¨hb.1.2, hb.2.2β©, β¨hb.1.1, hb.2.1β©]
#align vector_bundle.prod VectorBundle.prod
variable {π Fβ Eβ Fβ Eβ}
@[simp] -- porting note: changed arguments to make `simpNF` happy: merged `hxβ` and `hxβ` into `hx`
theorem Trivialization.continuousLinearEquivAt_prod {eβ : Trivialization Fβ (Ο Fβ Eβ)}
{eβ : Trivialization Fβ (Ο Fβ Eβ)} [eβ.IsLinear π] [eβ.IsLinear π] {x : B}
(hx : x β (eβ.prod eβ).baseSet) :
(eβ.prod eβ).continuousLinearEquivAt π x hx =
(eβ.continuousLinearEquivAt π x hx.1).prod (eβ.continuousLinearEquivAt π x hx.2) := by
ext v : 2
obtain β¨vβ, vββ© := v
rw [(eβ.prod eβ).continuousLinearEquivAt_apply π, Trivialization.prod]
exact (congr_arg Prod.snd (prod_apply π hx.1 hx.2 vβ vβ) : _)
#align trivialization.continuous_linear_equiv_at_prod Trivialization.continuousLinearEquivAt_prodβ
end
/-! ### Pullbacks of vector bundles -/
section
variable (R π : Type*) {B : Type*} (F : Type*) (E : B β Type*) {B' : Type*} (f : B' β B)
instance [i : β x : B, AddCommMonoid (E x)] (x : B') : AddCommMonoid ((f *α΅ E) x) := i _
instance [Semiring R] [β x : B, AddCommMonoid (E x)] [i : β x, Module R (E x)] (x : B') :
Module R ((f *α΅ E) x) := i _
variable {E F} [TopologicalSpace B'] [TopologicalSpace (TotalSpace F E)] [NontriviallyNormedField π]
[NormedAddCommGroup F] [NormedSpace π F] [TopologicalSpace B] [β x, AddCommMonoid (E x)]
[β x, Module π (E x)] {K : Type*} [ContinuousMapClass K B' B]
instance Trivialization.pullback_linear (e : Trivialization F (Ο F E)) [e.IsLinear π] (f : K) :
(@Trivialization.pullback _ _ _ B' _ _ _ _ _ _ _ e f).IsLinear π where
linear _ h := e.linear π h
#align trivialization.pullback_linear Trivialization.pullback_linear
instance VectorBundle.pullback [β x, TopologicalSpace (E x)] [FiberBundle F E] [VectorBundle π F E]
(f : K) : VectorBundle π F ((f : B' β B) *α΅ E) where
trivialization_linear' := by
rintro _ β¨e, he, rflβ©
infer_instance
continuousOn_coordChange' := by
rintro _ _ β¨e, he, rflβ© β¨e', he', rflβ©
refine' ((continuousOn_coordChange π e e').comp
(map_continuous f).continuousOn fun b hb => hb).congr _
rintro b (hb : f b β e.baseSet β© e'.baseSet); ext v
show ((e.pullback f).coordChangeL π (e'.pullback f) b) v = (e.coordChangeL π e' (f b)) v
| rw [e.coordChangeL_apply e' hb, (e.pullback f).coordChangeL_apply' _] | instance VectorBundle.pullback [β x, TopologicalSpace (E x)] [FiberBundle F E] [VectorBundle π F E]
(f : K) : VectorBundle π F ((f : B' β B) *α΅ E) where
trivialization_linear' := by
rintro _ β¨e, he, rflβ©
infer_instance
continuousOn_coordChange' := by
rintro _ _ β¨e, he, rflβ© β¨e', he', rflβ©
refine' ((continuousOn_coordChange π e e').comp
(map_continuous f).continuousOn fun b hb => hb).congr _
rintro b (hb : f b β e.baseSet β© e'.baseSet); ext v
show ((e.pullback f).coordChangeL π (e'.pullback f) b) v = (e.coordChangeL π e' (f b)) v
| Mathlib.Topology.VectorBundle.Constructions.184_0.ZrgS90NPsSlDzPQ | instance VectorBundle.pullback [β x, TopologicalSpace (E x)] [FiberBundle F E] [VectorBundle π F E]
(f : K) : VectorBundle π F ((f : B' β B) *α΅ E) where
trivialization_linear' | Mathlib_Topology_VectorBundle_Constructions |
case mk.intro.intro.mk.intro.intro.h
R : Type u_1
π : Type u_2
B : Type u_3
F : Type u_4
E : B β Type u_5
B' : Type u_6
fβ : B' β B
instβΒΉΒΉ : TopologicalSpace B'
instβΒΉβ° : TopologicalSpace (TotalSpace F E)
instββΉ : NontriviallyNormedField π
instββΈ : NormedAddCommGroup F
instββ· : NormedSpace π F
instββΆ : TopologicalSpace B
instββ΅ : (x : B) β AddCommMonoid (E x)
instββ΄ : (x : B) β Module π (E x)
K : Type u_7
instβΒ³ : ContinuousMapClass K B' B
instβΒ² : (x : B) β TopologicalSpace (E x)
instβΒΉ : FiberBundle F E
instβ : VectorBundle π F E
f : K
e : Trivialization F TotalSpace.proj
he : MemTrivializationAtlas e
e' : Trivialization F TotalSpace.proj
he' : MemTrivializationAtlas e'
b : B'
hb : f b β e.baseSet β© e'.baseSet
v : F
β’ (β(Trivialization.pullback e' f)
(β(PartialHomeomorph.symm (Trivialization.pullback e f).toPartialHomeomorph) (b, v))).2 =
(βe' { proj := f b, snd := Trivialization.symm e (f b) v }).2
case mk.intro.intro.mk.intro.intro.h.hb
R : Type u_1
π : Type u_2
B : Type u_3
F : Type u_4
E : B β Type u_5
B' : Type u_6
fβ : B' β B
instβΒΉΒΉ : TopologicalSpace B'
instβΒΉβ° : TopologicalSpace (TotalSpace F E)
instββΉ : NontriviallyNormedField π
instββΈ : NormedAddCommGroup F
instββ· : NormedSpace π F
instββΆ : TopologicalSpace B
instββ΅ : (x : B) β AddCommMonoid (E x)
instββ΄ : (x : B) β Module π (E x)
K : Type u_7
instβΒ³ : ContinuousMapClass K B' B
instβΒ² : (x : B) β TopologicalSpace (E x)
instβΒΉ : FiberBundle F E
instβ : VectorBundle π F E
f : K
e : Trivialization F TotalSpace.proj
he : MemTrivializationAtlas e
e' : Trivialization F TotalSpace.proj
he' : MemTrivializationAtlas e'
b : B'
hb : f b β e.baseSet β© e'.baseSet
v : F
β’ b β (Trivialization.pullback e f).baseSet β© (Trivialization.pullback e' f).baseSet | /-
Copyright Β© 2022 NicolΓ² Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: NicolΓ² Cavalleri, SΓ©bastien GouΓ«zel, Heather Macbeth, Floris van Doorn
-/
import Mathlib.Topology.FiberBundle.Constructions
import Mathlib.Topology.VectorBundle.Basic
#align_import topology.vector_bundle.constructions from "leanprover-community/mathlib"@"e473c3198bb41f68560cab68a0529c854b618833"
/-!
# Standard constructions on vector bundles
This file contains several standard constructions on vector bundles:
* `Bundle.Trivial.vectorBundle π B F`: the trivial vector bundle with scalar field `π` and model
fiber `F` over the base `B`
* `VectorBundle.prod`: for vector bundles `Eβ` and `Eβ` with scalar field `π` over a common base,
a vector bundle structure on their direct sum `Eβ Γα΅ Eβ` (the notation stands for
`fun x β¦ Eβ x Γ Eβ x`).
* `VectorBundle.pullback`: for a vector bundle `E` over `B`, a vector bundle structure on its
pullback `f *α΅ E` by a map `f : B' β B` (the notation is a type synonym for `E β f`).
## Tags
Vector bundle, direct sum, pullback
-/
noncomputable section
open Bundle Set FiberBundle Classical
/-! ### The trivial vector bundle -/
namespace Bundle.Trivial
variable (π : Type*) (B : Type*) (F : Type*) [NontriviallyNormedField π] [NormedAddCommGroup F]
[NormedSpace π F] [TopologicalSpace B]
instance trivialization.isLinear : (trivialization B F).IsLinear π where
linear _ _ := β¨fun _ _ => rfl, fun _ _ => rflβ©
#align bundle.trivial.trivialization.is_linear Bundle.Trivial.trivialization.isLinear
variable {π}
theorem trivialization.coordChangeL (b : B) :
(trivialization B F).coordChangeL π (trivialization B F) b =
ContinuousLinearEquiv.refl π F := by
ext v
rw [Trivialization.coordChangeL_apply']
exacts [rfl, β¨mem_univ _, mem_univ _β©]
set_option linter.uppercaseLean3 false in
#align bundle.trivial.trivialization.coord_changeL Bundle.Trivial.trivialization.coordChangeL
variable (π)
instance vectorBundle : VectorBundle π F (Bundle.Trivial B F) where
trivialization_linear' e he := by
rw [eq_trivialization B F e]
infer_instance
continuousOn_coordChange' e e' he he' := by
obtain rfl := eq_trivialization B F e
obtain rfl := eq_trivialization B F e'
simp only [trivialization.coordChangeL]
exact continuous_const.continuousOn
#align bundle.trivial.vector_bundle Bundle.Trivial.vectorBundle
end Bundle.Trivial
/-! ### Direct sum of two vector bundles -/
section
variable (π : Type*) {B : Type*} [NontriviallyNormedField π] [TopologicalSpace B] (Fβ : Type*)
[NormedAddCommGroup Fβ] [NormedSpace π Fβ] (Eβ : B β Type*) [TopologicalSpace (TotalSpace Fβ Eβ)]
(Fβ : Type*) [NormedAddCommGroup Fβ] [NormedSpace π Fβ] (Eβ : B β Type*)
[TopologicalSpace (TotalSpace Fβ Eβ)]
namespace Trivialization
variable {Fβ Eβ Fβ Eβ}
variable [β x, AddCommMonoid (Eβ x)] [β x, Module π (Eβ x)]
[β x, AddCommMonoid (Eβ x)] [β x, Module π (Eβ x)] (eβ eβ' : Trivialization Fβ (Ο Fβ Eβ))
(eβ eβ' : Trivialization Fβ (Ο Fβ Eβ))
instance prod.isLinear [eβ.IsLinear π] [eβ.IsLinear π] : (eβ.prod eβ).IsLinear π where
linear := fun _ β¨hβ, hββ© =>
(((eβ.linear π hβ).mk' _).prodMap ((eβ.linear π hβ).mk' _)).isLinear
#align trivialization.prod.is_linear Trivialization.prod.isLinear
@[simp]
theorem coordChangeL_prod [eβ.IsLinear π] [eβ'.IsLinear π] [eβ.IsLinear π] [eβ'.IsLinear π] β¦bβ¦
(hb : b β (eβ.prod eβ).baseSet β© (eβ'.prod eβ').baseSet) :
((eβ.prod eβ).coordChangeL π (eβ'.prod eβ') b : Fβ Γ Fβ βL[π] Fβ Γ Fβ) =
(eβ.coordChangeL π eβ' b : Fβ βL[π] Fβ).prodMap (eβ.coordChangeL π eβ' b) := by
rw [ContinuousLinearMap.ext_iff, ContinuousLinearMap.coe_prodMap']
rintro β¨vβ, vββ©
show
(eβ.prod eβ).coordChangeL π (eβ'.prod eβ') b (vβ, vβ) =
(eβ.coordChangeL π eβ' b vβ, eβ.coordChangeL π eβ' b vβ)
rw [eβ.coordChangeL_apply eβ', eβ.coordChangeL_apply eβ', (eβ.prod eβ).coordChangeL_apply']
exacts [rfl, hb, β¨hb.1.2, hb.2.2β©, β¨hb.1.1, hb.2.1β©]
set_option linter.uppercaseLean3 false in
#align trivialization.coord_changeL_prod Trivialization.coordChangeL_prod
variable {eβ eβ} [β x : B, TopologicalSpace (Eβ x)] [β x : B, TopologicalSpace (Eβ x)]
[FiberBundle Fβ Eβ] [FiberBundle Fβ Eβ]
theorem prod_apply [eβ.IsLinear π] [eβ.IsLinear π] {x : B} (hxβ : x β eβ.baseSet)
(hxβ : x β eβ.baseSet) (vβ : Eβ x) (vβ : Eβ x) :
prod eβ eβ β¨x, (vβ, vβ)β© =
β¨x, eβ.continuousLinearEquivAt π x hxβ vβ, eβ.continuousLinearEquivAt π x hxβ vββ© :=
rfl
#align trivialization.prod_apply Trivialization.prod_apply
end Trivialization
open Trivialization
variable [β x, AddCommMonoid (Eβ x)] [β x, Module π (Eβ x)] [β x, AddCommMonoid (Eβ x)]
[β x, Module π (Eβ x)] [β x : B, TopologicalSpace (Eβ x)] [β x : B, TopologicalSpace (Eβ x)]
[FiberBundle Fβ Eβ] [FiberBundle Fβ Eβ]
/-- The product of two vector bundles is a vector bundle. -/
instance VectorBundle.prod [VectorBundle π Fβ Eβ] [VectorBundle π Fβ Eβ] :
VectorBundle π (Fβ Γ Fβ) (Eβ Γα΅ Eβ) where
trivialization_linear' := by
rintro _ β¨eβ, eβ, heβ, heβ, rflβ©; skip
infer_instance
continuousOn_coordChange' := by
rintro _ _ β¨eβ, eβ, heβ, heβ, rflβ© β¨eβ', eβ', heβ', heβ', rflβ©; skip
refine' (((continuousOn_coordChange π eβ eβ').mono _).prod_mapL π
((continuousOn_coordChange π eβ eβ').mono _)).congr _ <;>
dsimp only [baseSet_prod, mfld_simps]
Β· mfld_set_tac
Β· mfld_set_tac
Β· rintro b hb
rw [ContinuousLinearMap.ext_iff]
rintro β¨vβ, vββ©
show (eβ.prod eβ).coordChangeL π (eβ'.prod eβ') b (vβ, vβ) =
(eβ.coordChangeL π eβ' b vβ, eβ.coordChangeL π eβ' b vβ)
rw [eβ.coordChangeL_apply eβ', eβ.coordChangeL_apply eβ', (eβ.prod eβ).coordChangeL_apply']
exacts [rfl, hb, β¨hb.1.2, hb.2.2β©, β¨hb.1.1, hb.2.1β©]
#align vector_bundle.prod VectorBundle.prod
variable {π Fβ Eβ Fβ Eβ}
@[simp] -- porting note: changed arguments to make `simpNF` happy: merged `hxβ` and `hxβ` into `hx`
theorem Trivialization.continuousLinearEquivAt_prod {eβ : Trivialization Fβ (Ο Fβ Eβ)}
{eβ : Trivialization Fβ (Ο Fβ Eβ)} [eβ.IsLinear π] [eβ.IsLinear π] {x : B}
(hx : x β (eβ.prod eβ).baseSet) :
(eβ.prod eβ).continuousLinearEquivAt π x hx =
(eβ.continuousLinearEquivAt π x hx.1).prod (eβ.continuousLinearEquivAt π x hx.2) := by
ext v : 2
obtain β¨vβ, vββ© := v
rw [(eβ.prod eβ).continuousLinearEquivAt_apply π, Trivialization.prod]
exact (congr_arg Prod.snd (prod_apply π hx.1 hx.2 vβ vβ) : _)
#align trivialization.continuous_linear_equiv_at_prod Trivialization.continuousLinearEquivAt_prodβ
end
/-! ### Pullbacks of vector bundles -/
section
variable (R π : Type*) {B : Type*} (F : Type*) (E : B β Type*) {B' : Type*} (f : B' β B)
instance [i : β x : B, AddCommMonoid (E x)] (x : B') : AddCommMonoid ((f *α΅ E) x) := i _
instance [Semiring R] [β x : B, AddCommMonoid (E x)] [i : β x, Module R (E x)] (x : B') :
Module R ((f *α΅ E) x) := i _
variable {E F} [TopologicalSpace B'] [TopologicalSpace (TotalSpace F E)] [NontriviallyNormedField π]
[NormedAddCommGroup F] [NormedSpace π F] [TopologicalSpace B] [β x, AddCommMonoid (E x)]
[β x, Module π (E x)] {K : Type*} [ContinuousMapClass K B' B]
instance Trivialization.pullback_linear (e : Trivialization F (Ο F E)) [e.IsLinear π] (f : K) :
(@Trivialization.pullback _ _ _ B' _ _ _ _ _ _ _ e f).IsLinear π where
linear _ h := e.linear π h
#align trivialization.pullback_linear Trivialization.pullback_linear
instance VectorBundle.pullback [β x, TopologicalSpace (E x)] [FiberBundle F E] [VectorBundle π F E]
(f : K) : VectorBundle π F ((f : B' β B) *α΅ E) where
trivialization_linear' := by
rintro _ β¨e, he, rflβ©
infer_instance
continuousOn_coordChange' := by
rintro _ _ β¨e, he, rflβ© β¨e', he', rflβ©
refine' ((continuousOn_coordChange π e e').comp
(map_continuous f).continuousOn fun b hb => hb).congr _
rintro b (hb : f b β e.baseSet β© e'.baseSet); ext v
show ((e.pullback f).coordChangeL π (e'.pullback f) b) v = (e.coordChangeL π e' (f b)) v
rw [e.coordChangeL_apply e' hb, (e.pullback f).coordChangeL_apply' _]
| exacts [rfl, hb] | instance VectorBundle.pullback [β x, TopologicalSpace (E x)] [FiberBundle F E] [VectorBundle π F E]
(f : K) : VectorBundle π F ((f : B' β B) *α΅ E) where
trivialization_linear' := by
rintro _ β¨e, he, rflβ©
infer_instance
continuousOn_coordChange' := by
rintro _ _ β¨e, he, rflβ© β¨e', he', rflβ©
refine' ((continuousOn_coordChange π e e').comp
(map_continuous f).continuousOn fun b hb => hb).congr _
rintro b (hb : f b β e.baseSet β© e'.baseSet); ext v
show ((e.pullback f).coordChangeL π (e'.pullback f) b) v = (e.coordChangeL π e' (f b)) v
rw [e.coordChangeL_apply e' hb, (e.pullback f).coordChangeL_apply' _]
| Mathlib.Topology.VectorBundle.Constructions.184_0.ZrgS90NPsSlDzPQ | instance VectorBundle.pullback [β x, TopologicalSpace (E x)] [FiberBundle F E] [VectorBundle π F E]
(f : K) : VectorBundle π F ((f : B' β B) *α΅ E) where
trivialization_linear' | Mathlib_Topology_VectorBundle_Constructions |
ΞΉ : 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f : M β N
p : M β Prop
h_mul : β (x y : M), p x β p y β f (x * y) β€ f x * f y
hp_mul : β (x y : M), p x β p y β p (x * y)
g : ΞΉ β M
s : Finset ΞΉ
hs_nonempty : Finset.Nonempty s
hs : β i β s, p (g i)
β’ f (β i in s, g i) β€ β i in s, f (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 _ _ _) _ | /-- 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
| Mathlib.Algebra.BigOperators.Order.33_0.ewL52iF1Dz3xeLh | /-- 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) | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f : M β N
p : M β Prop
h_mul : β (x y : M), p x β p y β f (x * y) β€ f x * f y
hp_mul : β (x y : M), p x β p y β p (x * y)
g : ΞΉ β M
s : Finset ΞΉ
hs_nonempty : Finset.Nonempty s
hs : β i β s, p (g i)
β’ Multiset.map (fun i => g i) s.val β β
| /-
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] | /-- 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 _ _ _) _
Β· | Mathlib.Algebra.BigOperators.Order.33_0.ewL52iF1Dz3xeLh | /-- 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) | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f : M β N
p : M β Prop
h_mul : β (x y : M), p x β p y β f (x * y) β€ f x * f y
hp_mul : β (x y : M), p x β p y β p (x * y)
g : ΞΉ β M
s : Finset ΞΉ
hs_nonempty : Finset.Nonempty s
hs : β i β s, p (g i)
β’ β a β Multiset.map (fun i => g i) s.val, p a | /-
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 | /-- 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]
Β· | Mathlib.Algebra.BigOperators.Order.33_0.ewL52iF1Dz3xeLh | /-- 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) | Mathlib_Algebra_BigOperators_Order |
case refine'_3
ΞΉ : 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f : M β N
p : M β Prop
h_mul : β (x y : M), p x β p y β f (x * y) β€ f x * f y
hp_mul : β (x y : M), p x β p y β p (x * y)
g : ΞΉ β M
s : Finset ΞΉ
hs_nonempty : Finset.Nonempty s
hs : β i β s, p (g i)
β’ Multiset.prod (Multiset.map f (Multiset.map (fun i => g i) s.val)) β€ β i in s, f (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] | /-- 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
| Mathlib.Algebra.BigOperators.Order.33_0.ewL52iF1Dz3xeLh | /-- 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) | Mathlib_Algebra_BigOperators_Order |
case refine'_3
ΞΉ : 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f : M β N
p : M β Prop
h_mul : β (x y : M), p x β p y β f (x * y) β€ f x * f y
hp_mul : β (x y : M), p x β p y β p (x * y)
g : ΞΉ β M
s : Finset ΞΉ
hs_nonempty : Finset.Nonempty s
hs : β i β s, p (g i)
β’ Multiset.prod (Multiset.map (f β fun i => g i) s.val) β€ β i in s, f (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 | /-- 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]
| Mathlib.Algebra.BigOperators.Order.33_0.ewL52iF1Dz3xeLh | /-- 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) | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f : M β N
p : M β Prop
h_one : f 1 = 1
h_mul : β (x y : M), p x β p y β f (x * y) β€ f x * f y
hp_mul : β (x y : M), 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) | /-
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) | /-- 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
| Mathlib.Algebra.BigOperators.Order.70_0.ewL52iF1Dz3xeLh | /-- 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) | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f : M β N
p : M β Prop
h_one : f 1 = 1
h_mul : β (x y : M), p x β p y β f (x * y) β€ f x * f y
hp_mul : β (x y : M), p x β p y β p (x * y)
g : ΞΉ β M
hs : β i β β
, p (g i)
β’ f (β i in β
, g i) β€ β i in β
, f (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] | /-- 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)
Β· | Mathlib.Algebra.BigOperators.Order.70_0.ewL52iF1Dz3xeLh | /-- 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) | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f : M β N
p : M β Prop
h_one : f 1 = 1
h_mul : β (x y : M), p x β p y β f (x * y) β€ f x * f y
hp_mul : β (x y : M), p x β p y β p (x * y)
g : ΞΉ β M
s : Finset ΞΉ
hs : β i β s, p (g i)
hs_nonempty : Finset.Nonempty s
β’ f (β i in s, g i) β€ β i in s, f (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 | /-- 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]
Β· | Mathlib.Algebra.BigOperators.Order.70_0.ewL52iF1Dz3xeLh | /-- 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) | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f : M β N
h_one : f 1 = 1
h_mul : β (x y : M), f (x * y) β€ f x * f y
s : Finset ΞΉ
g : ΞΉ β M
β’ f (β i in s, g i) β€ β i in s, f (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 _) _ | /-- 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
| Mathlib.Algebra.BigOperators.Order.90_0.ewL52iF1Dz3xeLh | /-- 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) | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f : M β N
h_one : f 1 = 1
h_mul : β (x y : M), f (x * y) β€ f x * f y
s : Finset ΞΉ
g : ΞΉ β M
β’ Multiset.prod (Multiset.map f (Multiset.map (fun i => g i) s.val)) β€ β i in s, f (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] | /-- 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 _) _
| Mathlib.Algebra.BigOperators.Order.90_0.ewL52iF1Dz3xeLh | /-- 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) | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f : M β N
h_one : f 1 = 1
h_mul : β (x y : M), f (x * y) β€ f x * f y
s : Finset ΞΉ
g : ΞΉ β M
β’ Multiset.prod (Multiset.map (f β fun i => g i) s.val) β€ β i in s, f (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 | /-- 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]
| Mathlib.Algebra.BigOperators.Order.90_0.ewL52iF1Dz3xeLh | /-- 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) | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f g : ΞΉ β N
s t : Finset ΞΉ
h : β i β s, 1 β€ f i
β’ 1 β€ β i in s, 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] | @[to_additive sum_nonneg]
theorem one_le_prod' (h : β i β s, 1 β€ f i) : 1 β€ β i in s, f i :=
le_trans (by | Mathlib.Algebra.BigOperators.Order.138_0.ewL52iF1Dz3xeLh | @[to_additive sum_nonneg]
theorem one_le_prod' (h : β i β s, 1 β€ f i) : 1 β€ β 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f g : ΞΉ β N
s t : Finset ΞΉ
h : β 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] | @[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 | Mathlib.Algebra.BigOperators.Order.150_0.ewL52iF1Dz3xeLh | @[to_additive sum_nonpos]
theorem prod_le_one' (h : β 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f g : ΞΉ β N
s t : Finset ΞΉ
h : s β t
hf : β i β t, i β s β 1 β€ f i
β’ β i in s, f i β€ β i in t, 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] | @[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
| Mathlib.Algebra.BigOperators.Order.156_0.ewL52iF1Dz3xeLh | @[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 | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f g : ΞΉ β N
s t : Finset ΞΉ
h : s β t
hf : β i β t, i β s β 1 β€ f i
β’ β i in s, f i β€ β i in t, 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] | @[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 | Mathlib.Algebra.BigOperators.Order.156_0.ewL52iF1Dz3xeLh | @[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 | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f g : ΞΉ β N
s t : Finset ΞΉ
h : s β t
hf : β i β t, i β s β 1 β€ f i
β’ β i β t \ s, 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] | @[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 | Mathlib.Algebra.BigOperators.Order.156_0.ewL52iF1Dz3xeLh | @[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 | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f g : ΞΉ β N
s t : Finset ΞΉ
h : s β t
hf : β i β t, i β s β 1 β€ f i
β’ β i in t \ s βͺ s, f i = β i in t, 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] | @[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 | Mathlib.Algebra.BigOperators.Order.156_0.ewL52iF1Dz3xeLh | @[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 | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f g : ΞΉ β N
s t : Finset ΞΉ
β’ (β i β s, 1 β€ f i) β (β i in s, f i = 1 β β i β s, 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] | @[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
| Mathlib.Algebra.BigOperators.Order.181_0.ewL52iF1Dz3xeLh | @[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) | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f g : ΞΉ β N
s t : Finset ΞΉ
β’ (β i β s, 1 β€ f i) β (β i in s, f i = 1 β β i β s, 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β©) ?_ | @[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
| Mathlib.Algebra.BigOperators.Order.181_0.ewL52iF1Dz3xeLh | @[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) | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f g : ΞΉ β N
s t : Finset ΞΉ
β’ β β¦a : ΞΉβ¦ {s : Finset ΞΉ},
a β s β
((β i β s, 1 β€ f i) β (β i in s, f i = 1 β β i β s, f i = 1)) β
(β i β insert a s, 1 β€ f i) β (β i in insert a s, f i = 1 β β i β insert a s, 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 | @[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β©) ?_
| Mathlib.Algebra.BigOperators.Order.181_0.ewL52iF1Dz3xeLh | @[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) | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f g : ΞΉ β N
sβ t : Finset ΞΉ
a : ΞΉ
s : Finset ΞΉ
ha : a β s
ih : (β i β s, 1 β€ f i) β (β i in s, f i = 1 β β i β s, f i = 1)
H : β i β insert a s, 1 β€ f i
β’ β i in insert a s, f i = 1 β β i β insert a s, 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 | @[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
| Mathlib.Algebra.BigOperators.Order.181_0.ewL52iF1Dz3xeLh | @[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) | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f g : ΞΉ β N
sβ t : Finset ΞΉ
a : ΞΉ
s : Finset ΞΉ
ha : a β s
ih : (β i β s, 1 β€ f i) β (β i in s, f i = 1 β β i β s, f i = 1)
H : β i β insert a s, 1 β€ f i
this : β i β s, 1 β€ f i
β’ β i in insert a s, f i = 1 β β i β insert a s, 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] | @[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
| Mathlib.Algebra.BigOperators.Order.181_0.ewL52iF1Dz3xeLh | @[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) | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f g : ΞΉ β N
s t : Finset ΞΉ
i j : ΞΉ
hf : β i β s, 1 β€ f i
hi : i β s
hj : j β s
hne : i β j
β’ i β {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 | @[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 | Mathlib.Algebra.BigOperators.Order.211_0.ewL52iF1Dz3xeLh | @[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 | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f g : ΞΉ β N
s t : Finset ΞΉ
i j : ΞΉ
hf : β i β s, 1 β€ f i
hi : i β s
hj : j β s
hne : i β j
β’ f i * f j = β k in cons i {j} (_ : i β {j}), f k | /-
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] | @[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 | Mathlib.Algebra.BigOperators.Order.211_0.ewL52iF1Dz3xeLh | @[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 | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f g : ΞΉ β N
s t : Finset ΞΉ
i j : ΞΉ
hf : β i β s, 1 β€ f i
hi : i β s
hj : j β s
hne : i β j
β’ β k in cons i {j} (_ : i β {j}), f k β€ β k in s, f k | /-
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 | @[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
| Mathlib.Algebra.BigOperators.Order.211_0.ewL52iF1Dz3xeLh | @[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 | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
f g : ΞΉ β N
s t : Finset ΞΉ
i j : ΞΉ
hf : β i β s, 1 β€ f i
hi : i β s
hj : j β s
hne : i β j
β’ cons i {j} (_ : i β {j}) β 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]
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
| Mathlib.Algebra.BigOperators.Order.211_0.ewL52iF1Dz3xeLh | @[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 | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
fβ g : ΞΉ β N
sβ t s : Finset ΞΉ
f : ΞΉ β N
n : N
h : β x β s, f x β€ n
β’ Finset.prod s f β€ n ^ card 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 _ | @[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
| Mathlib.Algebra.BigOperators.Order.220_0.ewL52iF1Dz3xeLh | @[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 | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
fβ g : ΞΉ β N
sβ t s : Finset ΞΉ
f : ΞΉ β N
n : N
h : β x β s, f x β€ n
β’ β x β Multiset.map f s.val, x β€ n | /-
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 | @[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 _
Β· | Mathlib.Algebra.BigOperators.Order.220_0.ewL52iF1Dz3xeLh | @[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 | 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βΒΉ : CommMonoid M
instβ : OrderedCommMonoid N
fβ g : ΞΉ β N
sβ t s : Finset ΞΉ
f : ΞΉ β N
n : N
h : β x β s, f x β€ n
β’ n ^ Multiset.card (Multiset.map f s.val) β€ n ^ card 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 | @[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
Β· | Mathlib.Algebra.BigOperators.Order.220_0.ewL52iF1Dz3xeLh | @[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 | 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
G : Type u_9
instβ : LinearOrderedAddCommGroup G
f : ΞΉ β G
s : Finset ΞΉ
hf : β i β s, 0 β€ f i
β’ |β i in s, f 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)] | 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
| Mathlib.Algebra.BigOperators.Order.271_0.ewL52iF1Dz3xeLh | 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 | 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
G : Type u_9
instβ : LinearOrderedAddCommGroup G
f : ΞΉ β G
s : Finset ΞΉ
hf : β (i : ΞΉ), 0 β€ f i
β’ |β i in s, f 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)] | 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
| Mathlib.Algebra.BigOperators.Order.276_0.ewL52iF1Dz3xeLh | 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 | 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β : DecidableEq Ξ²
f : Ξ± β Ξ²
s : Finset Ξ±
t : Finset Ξ²
Hf : β a β s, f a β t
n : β
hn : β a β t, card (filter (fun x => f x = a) s) β€ n
β’ β _a in t, n = n * card t | /-
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] | 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 | Mathlib.Algebra.BigOperators.Order.290_0.ewL52iF1Dz3xeLh | 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 | 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β : DecidableEq Ξ²
f : Ξ± β Ξ²
s : Finset Ξ±
t : Finset Ξ²
Hf : β a β s, f a β t
n : β
hn : β a β t, n β€ card (filter (fun x => f x = a) s)
β’ n * card t = β _a in t, n | /-
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] | 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 | Mathlib.Algebra.BigOperators.Order.304_0.ewL52iF1Dz3xeLh | 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 | 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β : DecidableEq Ξ²
f : Ξ± β Ξ²
s : Finset Ξ±
t : Finset Ξ²
Hf : β a β s, f a β t
n : β
hn : β a β t, n β€ card (filter (fun x => f x = a) s)
β’ β a in t, card (filter (fun x => f x = a) s) = card 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] | 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 | Mathlib.Algebra.BigOperators.Order.304_0.ewL52iF1Dz3xeLh | 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 | 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β : DecidableEq Ξ±
s : Finset Ξ±
B : Finset (Finset Ξ±)
n : β
h : β a β s, card (filter (fun x => a β x) B) β€ n
β’ β t in B, card (s β© t) β€ card s * n | /-
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) | /-- 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
| Mathlib.Algebra.BigOperators.Order.324_0.ewL52iF1Dz3xeLh | /-- 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 | 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β : DecidableEq Ξ±
s : Finset Ξ±
B : Finset (Finset Ξ±)
n : β
h : β a β s, card (filter (fun x => a β x) B) β€ n
β’ β t in B, card (s β© t) β€ β x in s, card (filter (fun x_1 => x β x_1) B) | /-
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] | /-- 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)
| Mathlib.Algebra.BigOperators.Order.324_0.ewL52iF1Dz3xeLh | /-- 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 | 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β : DecidableEq Ξ±
s : Finset Ξ±
B : Finset (Finset Ξ±)
n : β
h : β a β s, card (filter (fun x => a β x) B) β€ n
β’ (β x in B, β a in s, if a β x then 1 else 0) β€ β x in s, β a in B, if x β a then 1 else 0 | /-
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 | /-- 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]
| Mathlib.Algebra.BigOperators.Order.324_0.ewL52iF1Dz3xeLh | /-- 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 | 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βΒΉ : DecidableEq Ξ±
s : Finset Ξ±
B : Finset (Finset Ξ±)
n : β
instβ : Fintype Ξ±
h : β (a : Ξ±), card (filter (fun x => a β x) B) β€ n
β’ β s in B, card s = β s in B, card (univ β© 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] | /-- 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 | Mathlib.Algebra.BigOperators.Order.333_0.ewL52iF1Dz3xeLh | /-- 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 | 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β : DecidableEq Ξ±
s : Finset Ξ±
B : Finset (Finset Ξ±)
n : β
h : β a β s, n β€ card (filter (fun x => a β x) B)
β’ card s * n β€ β t in B, card (s β© t) | /-
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 | /-- 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
| Mathlib.Algebra.BigOperators.Order.342_0.ewL52iF1Dz3xeLh | /-- 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 | 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β : DecidableEq Ξ±
s : Finset Ξ±
B : Finset (Finset Ξ±)
n : β
h : β a β s, n β€ card (filter (fun x => a β x) B)
β’ β x in s, card (filter (fun x_1 => x β x_1) B) β€ β t in B, card (s β© t) | /-
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] | /-- 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
| Mathlib.Algebra.BigOperators.Order.342_0.ewL52iF1Dz3xeLh | /-- 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 | 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β : DecidableEq Ξ±
s : Finset Ξ±
B : Finset (Finset Ξ±)
n : β
h : β a β s, n β€ card (filter (fun x => a β x) B)
β’ (β x in s, β a in B, if x β a then 1 else 0) β€ β x in B, β a in s, if a β x then 1 else 0 | /-
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 | /-- 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]
| Mathlib.Algebra.BigOperators.Order.342_0.ewL52iF1Dz3xeLh | /-- 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 | 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βΒΉ : DecidableEq Ξ±
s : Finset Ξ±
B : Finset (Finset Ξ±)
n : β
instβ : Fintype Ξ±
h : β (a : Ξ±), n β€ card (filter (fun x => a β x) B)
β’ β s in B, card (univ β© s) = β s in B, card 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] | /-- 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 | Mathlib.Algebra.BigOperators.Order.351_0.ewL52iF1Dz3xeLh | /-- 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 | 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βΒΉ : DecidableEq Ξ±
s : Finset Ξ±
B : Finset (Finset Ξ±)
n : β
instβ : Fintype Ξ±
h : β (a : Ξ±), card (filter (fun x => a β x) B) = n
β’ β s in B, card s = Fintype.card Ξ± * n | /-
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] | /-- 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
| Mathlib.Algebra.BigOperators.Order.367_0.ewL52iF1Dz3xeLh | /-- 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 | 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β : DecidableEq Ξ±
sβ : Finset Ξ±
B : Finset (Finset Ξ±)
n : β
s : Finset ΞΉ
f : ΞΉ β Finset Ξ±
hs : Set.PairwiseDisjoint (βs) f
hf : β i β s, Finset.Nonempty (f i)
β’ card s β€ card (Finset.biUnion s 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] | 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
| Mathlib.Algebra.BigOperators.Order.374_0.ewL52iF1Dz3xeLh | 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 | 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β : DecidableEq Ξ±
sβ : Finset Ξ±
B : Finset (Finset Ξ±)
n : β
s : Finset ΞΉ
f : ΞΉ β Finset Ξ±
hs : Set.PairwiseDisjoint (βs) f
hf : β i β s, Finset.Nonempty (f i)
β’ β x in s, 1 β€ β u in s, card (f u) | /-
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 | 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]
| Mathlib.Algebra.BigOperators.Order.374_0.ewL52iF1Dz3xeLh | 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 | 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β : DecidableEq Ξ±
sβ : Finset Ξ±
B : Finset (Finset Ξ±)
n : β
s : Finset ΞΉ
f : ΞΉ β Finset Ξ±
hs : Set.PairwiseDisjoint (βs) f
β’ card s β€ card (Finset.biUnion s f) + card (filter (fun i => f 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] | 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
| Mathlib.Algebra.BigOperators.Order.380_0.ewL52iF1Dz3xeLh | 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 | 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β : DecidableEq Ξ±
sβ : Finset Ξ±
B : Finset (Finset Ξ±)
n : β
s : Finset ΞΉ
f : ΞΉ β Finset Ξ±
hs : Set.PairwiseDisjoint (βs) f
β’ card (filter (fun a => Β¬f a = β
) s) + card (filter (fun i => f i = β
) s) β€
card (Finset.biUnion s f) + card (filter (fun i => f 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 _ _)
_ | 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]
| Mathlib.Algebra.BigOperators.Order.380_0.ewL52iF1Dz3xeLh | 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 | 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β : CanonicallyOrderedCommMonoid M
f : ΞΉ β M
s t : Finset ΞΉ
h : β x β s, f x β 1 β x β t
β’ β x in s, f x β€ β x in t, 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] ) | @[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
| Mathlib.Algebra.BigOperators.Order.423_0.ewL52iF1Dz3xeLh | @[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 | 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β : CanonicallyOrderedCommMonoid M
f : ΞΉ β M
s t : Finset ΞΉ
h : β x β s, f x β 1 β x β t
β’ β x in s, f x β€ β x in t, 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] ) | @[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 | Mathlib.Algebra.BigOperators.Order.423_0.ewL52iF1Dz3xeLh | @[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 | 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β : CanonicallyOrderedCommMonoid M
f : ΞΉ β M
s t : Finset ΞΉ
h : β x β s, f x β 1 β x β t
β’ β x in s, f x = (β x in filter (fun x => f x = 1) s, f x) * β x in filter (fun x => f x β 1) s, f x | /-
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] | @[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
| Mathlib.Algebra.BigOperators.Order.423_0.ewL52iF1Dz3xeLh | @[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 | 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β : CanonicallyOrderedCommMonoid M
f : ΞΉ β M
s t : Finset ΞΉ
h : β x β s, f x β 1 β x β t
β’ Disjoint (filter (fun x => f x = 1) s) (filter (fun x => f x β 1) 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 | @[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]
| Mathlib.Algebra.BigOperators.Order.423_0.ewL52iF1Dz3xeLh | @[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 | 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β : CanonicallyOrderedCommMonoid M
f : ΞΉ β M
s t : Finset ΞΉ
h : β x β s, f x β 1 β x β t
β’ β i β filter (fun x => f x = 1) s, 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] | @[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 | Mathlib.Algebra.BigOperators.Order.423_0.ewL52iF1Dz3xeLh | @[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 | 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β : CanonicallyOrderedCommMonoid M
f : ΞΉ β M
s t : Finset ΞΉ
h : β x β s, f x β 1 β x β t
β’ β i β s, f 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 | @[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]; | Mathlib.Algebra.BigOperators.Order.423_0.ewL52iF1Dz3xeLh | @[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 | 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β : CanonicallyOrderedCommMonoid M
f : ΞΉ β M
s t : Finset ΞΉ
h : β x β s, f x β 1 β x β t
β’ filter (fun x => f x β 1) s β t | /-
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] | @[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 | Mathlib.Algebra.BigOperators.Order.423_0.ewL52iF1Dz3xeLh | @[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 | 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β : OrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
hs : Finset.Nonempty s
hlt : β i β s, f i < g i
β’ s.val β β
| /-
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 | @[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 | Mathlib.Algebra.BigOperators.Order.451_0.ewL52iF1Dz3xeLh | @[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 | 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β : OrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
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 | /-
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 | @[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
| Mathlib.Algebra.BigOperators.Order.478_0.ewL52iF1Dz3xeLh | @[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 | 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β : OrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
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 | /-
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 | @[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 | Mathlib.Algebra.BigOperators.Order.478_0.ewL52iF1Dz3xeLh | @[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 | 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β : OrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
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 insert i s, 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] | @[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
| Mathlib.Algebra.BigOperators.Order.478_0.ewL52iF1Dz3xeLh | @[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 | 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β : OrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
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 < f i * β x in s, 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 | @[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]
| Mathlib.Algebra.BigOperators.Order.478_0.ewL52iF1Dz3xeLh | @[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 | 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β : OrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
h : s β t
i : ΞΉ
ht : i β t
hs : i β s
hlt : 1 < f i
hle : β j β t, j β s β 1 β€ f j
β’ β j in insert i s, f j β€ β j in t, 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' | @[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
| Mathlib.Algebra.BigOperators.Order.478_0.ewL52iF1Dz3xeLh | @[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 | 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β : OrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
h : s β t
i : ΞΉ
ht : i β t
hs : i β s
hlt : 1 < f i
hle : β j β t, j β s β 1 β€ f j
β’ insert i s β t | /-
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] | @[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'
Β· | Mathlib.Algebra.BigOperators.Order.478_0.ewL52iF1Dz3xeLh | @[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 | Mathlib_Algebra_BigOperators_Order |
case hf
ΞΉ : 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β : OrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
h : s β t
i : ΞΉ
ht : i β t
hs : i β s
hlt : 1 < f i
hle : β j β t, j β s β 1 β€ f j
β’ β i_1 β t, i_1 β insert i s β 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 | @[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]
Β· | Mathlib.Algebra.BigOperators.Order.478_0.ewL52iF1Dz3xeLh | @[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 | Mathlib_Algebra_BigOperators_Order |
case hf
ΞΉ : 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β : OrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
h : s β t
i : ΞΉ
ht : i β t
hs : i β s
hlt : 1 < f i
hle : β j β t, j β s β 1 β€ f j
x : ΞΉ
hx : x β t
h'x : x β insert i s
β’ 1 β€ 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 | @[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
| Mathlib.Algebra.BigOperators.Order.478_0.ewL52iF1Dz3xeLh | @[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 | Mathlib_Algebra_BigOperators_Order |
case hf
ΞΉ : 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β : OrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
h : s β t
i : ΞΉ
ht : i β t
hs : i β s
hlt : 1 < f i
hle : β j β t, j β s β 1 β€ f j
x : ΞΉ
hx : x β t
h'x : Β¬x = i β§ x β s
β’ 1 β€ 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 | @[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
| Mathlib.Algebra.BigOperators.Order.478_0.ewL52iF1Dz3xeLh | @[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 | 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β : OrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
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 {i}, f k | /-
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] | @[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 | Mathlib.Algebra.BigOperators.Order.494_0.ewL52iF1Dz3xeLh | @[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 | 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β : OrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
h : β i β s, 1 < f i
hs : Finset.Nonempty s
β’ 1 β€ β i in s, 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] | @[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 | Mathlib.Algebra.BigOperators.Order.505_0.ewL52iF1Dz3xeLh | @[to_additive sum_pos]
theorem one_lt_prod (h : β i β s, 1 < f i) (hs : s.Nonempty) : 1 < β 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β : OrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
h : β i β s, f i < 1
hs : Finset.Nonempty s
β’ β 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] | @[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 | Mathlib.Algebra.BigOperators.Order.511_0.ewL52iF1Dz3xeLh | @[to_additive]
theorem prod_lt_one (h : β i β s, f i < 1) (hs : s.Nonempty) : β 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β : OrderedCancelCommMonoid M
fβ gβ : ΞΉ β M
s t : Finset ΞΉ
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 | /-
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) | @[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
| Mathlib.Algebra.BigOperators.Order.529_0.ewL52iF1Dz3xeLh | @[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 | 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β : OrderedCancelCommMonoid M
fβ gβ : ΞΉ β M
s t : Finset ΞΉ
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 | /-
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 | @[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
| Mathlib.Algebra.BigOperators.Order.529_0.ewL52iF1Dz3xeLh | @[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 | 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β : OrderedCancelCommMonoid M
fβ gβ : ΞΉ β M
s t : Finset ΞΉ
f g : ΞΉ β M
β’ (β i β s, f i β€ g i) β (β i in s, f i = β i in s, g i β β 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 β¦ ?_ | @[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
| Mathlib.Algebra.BigOperators.Order.529_0.ewL52iF1Dz3xeLh | @[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 | 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β : OrderedCancelCommMonoid M
fβ gβ : ΞΉ β M
sβ t : Finset ΞΉ
f g : ΞΉ β M
a : ΞΉ
s : Finset ΞΉ
ha : a β s
ih : (β i β s, f i β€ g i) β (β i in s, f i = β i in s, g i β β i β s, f i = g i)
H : β i β insert a s, f i β€ g i
β’ β i in insert a s, f i = β i in insert a s, g i β β i β insert a 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 | @[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 β¦ ?_
| Mathlib.Algebra.BigOperators.Order.529_0.ewL52iF1Dz3xeLh | @[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 | 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β : OrderedCancelCommMonoid M
fβ gβ : ΞΉ β M
sβ t : Finset ΞΉ
f g : ΞΉ β M
a : ΞΉ
s : Finset ΞΉ
ha : a β s
H : β i β insert a s, f i β€ g i
ih : β i in s, f i = β i in s, g i β β i β s, f i = g i
β’ β i in insert a s, f i = β i in insert a s, g i β β i β insert a 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] | @[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
| Mathlib.Algebra.BigOperators.Order.529_0.ewL52iF1Dz3xeLh | @[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 | 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β : OrderedCancelCommMonoid M
fβ gβ : ΞΉ β M
sβ t : Finset ΞΉ
f g : ΞΉ β M
a : ΞΉ
s : Finset ΞΉ
ha : a β s
H : β i β insert a s, f i β€ g i
ih : β i in s, f i = β i in s, g i β β i β s, f i = g i
β’ f a * β x in s, f x = g a * β x in s, g x β f a = g a β§ β i in s, f i = β i in s, g i | /-
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) | @[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]
| Mathlib.Algebra.BigOperators.Order.529_0.ewL52iF1Dz3xeLh | @[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 | 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βΒΉ : OrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
instβ : DecidableEq ΞΉ
β’ β i in s \ t, f i β€ β i in t \ s, f i β β i in s, f i β€ β i in t, 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] | @[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
| Mathlib.Algebra.BigOperators.Order.546_0.ewL52iF1Dz3xeLh | @[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 | 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βΒΉ : OrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
instβ : DecidableEq ΞΉ
β’ Disjoint (t \ s) (s β© t) | /-
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_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];
| Mathlib.Algebra.BigOperators.Order.546_0.ewL52iF1Dz3xeLh | @[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 | 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βΒΉ : OrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
instβ : DecidableEq ΞΉ
β’ β i in s \ t, f i < β i in t \ s, f i β β i in s, f i < β i in t, 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] | @[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
| Mathlib.Algebra.BigOperators.Order.552_0.ewL52iF1Dz3xeLh | @[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 | 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βΒΉ : OrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
instβ : DecidableEq ΞΉ
β’ Disjoint (t \ s) (s β© t) | /-
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 | @[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];
| Mathlib.Algebra.BigOperators.Order.552_0.ewL52iF1Dz3xeLh | @[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 | 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β : LinearOrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
Hlt : β i in s, f i < β i in s, g i
β’ β 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 | @[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
| Mathlib.Algebra.BigOperators.Order.564_0.ewL52iF1Dz3xeLh | @[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 | 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β : LinearOrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
Hle : β i β s, g i β€ f i
β’ β i in s, g 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 | @[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
| Mathlib.Algebra.BigOperators.Order.564_0.ewL52iF1Dz3xeLh | @[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 | 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β : LinearOrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
hs : Finset.Nonempty s
Hle : β i in s, f i β€ β i in s, g i
β’ β 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 | @[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
| Mathlib.Algebra.BigOperators.Order.571_0.ewL52iF1Dz3xeLh | @[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 | 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β : LinearOrderedCancelCommMonoid M
f g : ΞΉ β M
s t : Finset ΞΉ
hs : Finset.Nonempty s
Hlt : β i β s, g i < f i
β’ β i in s, g 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 | @[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
| Mathlib.Algebra.BigOperators.Order.571_0.ewL52iF1Dz3xeLh | @[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 | 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β : LinearOrderedCancelCommMonoid M
fβ g : ΞΉ β M
s t : Finset ΞΉ
f : ΞΉ β M
hβ : β i in s, f i = 1
hβ : β i β s, f i β 1
β’ β i β s, 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β | @[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
| Mathlib.Algebra.BigOperators.Order.579_0.ewL52iF1Dz3xeLh | @[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 | 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β : LinearOrderedCancelCommMonoid M
fβ g : ΞΉ β M
s t : Finset ΞΉ
f : ΞΉ β M
hβ : β i β s, f i β 1
hβ : β i β s, f i β€ 1
β’ β i in s, 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β | @[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β
| Mathlib.Algebra.BigOperators.Order.579_0.ewL52iF1Dz3xeLh | @[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 | 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β : LinearOrderedCancelCommMonoid M
fβ g : ΞΉ β M
s t : Finset ΞΉ
f : ΞΉ β M
hβ : β i β s, f i β€ 1
i : ΞΉ
m : i β s
i_ne : f i β 1
β’ β i in s, 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 | @[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β
| Mathlib.Algebra.BigOperators.Order.579_0.ewL52iF1Dz3xeLh | @[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 | Mathlib_Algebra_BigOperators_Order |
case intro.intro.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β : LinearOrderedCancelCommMonoid M
fβ g : ΞΉ β M
s t : Finset ΞΉ
f : ΞΉ β M
hβ : β i β s, f i β€ 1
i : ΞΉ
m : i β s
i_ne : f i β 1
β’ β i in s, 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 | @[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
| Mathlib.Algebra.BigOperators.Order.579_0.ewL52iF1Dz3xeLh | @[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 | 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 ΞΉ
h0 : β i β s, 0 β€ f i
h1 : β 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 | /-- 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
| Mathlib.Algebra.BigOperators.Order.604_0.ewL52iF1Dz3xeLh | /-- 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 | 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β : OrderedCommSemiring R
f g : ΞΉ β R
s t : Finset ΞΉ
h0 : β i β β
, 0 β€ f i
h1 : β i β β
, f i β€ g i
β’ β i in β
, f i β€ β i in β
, 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 | /-- 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
Β· | Mathlib.Algebra.BigOperators.Order.604_0.ewL52iF1Dz3xeLh | /-- 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 | Mathlib_Algebra_BigOperators_Order |
case insert
ΞΉ : 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 ΞΉ
a : ΞΉ
s : Finset ΞΉ
has : a β s
ih : (β i β s, 0 β€ f i) β (β i β s, f i β€ g i) β β i in s, f i β€ β i in s, g i
h0 : β i β insert a s, 0 β€ f i
h1 : β i β insert a s, f i β€ g i
β’ β i in insert a s, f i β€ β i in insert a 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] | /-- 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
Β· | Mathlib.Algebra.BigOperators.Order.604_0.ewL52iF1Dz3xeLh | /-- 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 | Mathlib_Algebra_BigOperators_Order |
case insert
ΞΉ : 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 ΞΉ
a : ΞΉ
s : Finset ΞΉ
has : a β s
ih : (β i β s, 0 β€ f i) β (β i β s, f i β€ g i) β β i in s, f i β€ β i in s, g i
h0 : β i β insert a s, 0 β€ f i
h1 : β i β insert a s, f i β€ g i
β’ f a * β i in s, f i β€ g a * β 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 | /-- 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]
| Mathlib.Algebra.BigOperators.Order.604_0.ewL52iF1Dz3xeLh | /-- 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 | Mathlib_Algebra_BigOperators_Order |
case insert.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β : OrderedCommSemiring R
f g : ΞΉ β R
sβ t : Finset ΞΉ
a : ΞΉ
s : Finset ΞΉ
has : a β s
ih : (β i β s, 0 β€ f i) β (β i β s, f i β€ g i) β β i in s, f i β€ β i in s, g i
h0 : β i β insert a s, 0 β€ f i
h1 : β i β insert a s, f i β€ g i
β’ f a β€ g a | /-
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) | /-- 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
Β· | Mathlib.Algebra.BigOperators.Order.604_0.ewL52iF1Dz3xeLh | /-- 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 | Mathlib_Algebra_BigOperators_Order |
case insert.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β : OrderedCommSemiring R
f g : ΞΉ β R
sβ t : Finset ΞΉ
a : ΞΉ
s : Finset ΞΉ
has : a β s
ih : (β i β s, 0 β€ f i) β (β i β s, f i β€ g i) β β i in s, f i β€ β i in s, g i
h0 : β i β insert a s, 0 β€ f i
h1 : β i β insert a 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 _ ?_) | /-- 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)
Β· | Mathlib.Algebra.BigOperators.Order.604_0.ewL52iF1Dz3xeLh | /-- 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 | Mathlib_Algebra_BigOperators_Order |
case insert.hβ.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 ΞΉ
a : ΞΉ
s : Finset ΞΉ
has : a β s
ih : (β i β s, 0 β€ f i) β (β i β s, f i β€ g i) β β i in s, f i β€ β i in s, g i
h0 : β i β insert a s, 0 β€ f i
h1 : β i β insert a s, f i β€ g i
x : ΞΉ
H : x β s
β’ x β insert a 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 | /-- 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 _ ?_) <;> | Mathlib.Algebra.BigOperators.Order.604_0.ewL52iF1Dz3xeLh | /-- 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 | Mathlib_Algebra_BigOperators_Order |
case insert.hβ.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 ΞΉ
a : ΞΉ
s : Finset ΞΉ
has : a β s
ih : (β i β s, 0 β€ f i) β (β i β s, f i β€ g i) β β i in s, f i β€ β i in s, g i
h0 : β i β insert a s, 0 β€ f i
h1 : β i β insert a s, f i β€ g i
x : ΞΉ
H : x β s
β’ x β insert a 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 | /-- 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 _ ?_) <;> | Mathlib.Algebra.BigOperators.Order.604_0.ewL52iF1Dz3xeLh | /-- 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 | Mathlib_Algebra_BigOperators_Order |
case insert.c0
ΞΉ : 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 ΞΉ
a : ΞΉ
s : Finset ΞΉ
has : a β s
ih : (β i β s, 0 β€ f i) β (β i β s, f i β€ g i) β β i in s, f i β€ β i in s, g i
h0 : β i β insert a s, 0 β€ f i
h1 : β i β insert a s, f i β€ g i
β’ 0 β€ β 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) | /-- 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
Β· | Mathlib.Algebra.BigOperators.Order.604_0.ewL52iF1Dz3xeLh | /-- 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 | Mathlib_Algebra_BigOperators_Order |
case insert.b0
ΞΉ : 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 ΞΉ
a : ΞΉ
s : Finset ΞΉ
has : a β s
ih : (β i β s, 0 β€ f i) β (β i β s, f i β€ g i) β β i in s, f i β€ β i in s, g i
h0 : β i β insert a s, 0 β€ f i
h1 : β i β insert a s, f i β€ g i
β’ 0 β€ g a | /-
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)) | /-- 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)
Β· | Mathlib.Algebra.BigOperators.Order.604_0.ewL52iF1Dz3xeLh | /-- 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 | 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 ΞΉ
h0 : β i β s, 0 β€ f i
h1 : β i β s, f i β€ 1
β’ β i in s, 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 | /-- 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
| 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.