state
stringlengths 0
159k
| srcUpToTactic
stringlengths 387
167k
| nextTactic
stringlengths 3
9k
| declUpToTactic
stringlengths 22
11.5k
| declId
stringlengths 38
95
| decl
stringlengths 16
1.89k
| file_tag
stringlengths 17
73
|
---|---|---|---|---|---|---|
case h.e'_3
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxaβ : x β a
hyaβ : y β a
hxyβ : x β€ y
hxy : x < y
hxa : x < a
hya : y > a
β’ -(f x - f a) / -(x - a) = (f a - f x) / (a - x) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; | field_simp | theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; | Mathlib.Analysis.Convex.Slope.266_0.2UqTeSfXEWgn9kZ | theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) | Mathlib_Analysis_Convex_Slope |
case inr.inr
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxaβ : x β a
hya : y β a
hxyβ : x β€ y
hxy : x < y
hxa : x > a
β’ (f x - f a) / (x - a) β€ (f y - f a) / (y - a) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· | exact hf.secant_mono_aux2 ha hy hxa hxy | theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· | Mathlib.Analysis.Convex.Slope.266_0.2UqTeSfXEWgn9kZ | theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
β’ (z - x) * f y < (z - y) * f x + (y - x) * f z | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
| have hxy' : 0 < y - x := by linarith | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
| Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
β’ 0 < y - x | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by | linarith | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by | Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
β’ (z - x) * f y < (z - y) * f x + (y - x) * f z | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
| have hyz' : 0 < z - y := by linarith | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
| Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
β’ 0 < z - y | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by | linarith | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by | Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
hyz' : 0 < z - y
β’ (z - x) * f y < (z - y) * f x + (y - x) * f z | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
| have hxz' : 0 < z - x := by linarith | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
| Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
hyz' : 0 < z - y
β’ 0 < z - x | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by | linarith | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by | Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
hyz' : 0 < z - y
hxz' : 0 < z - x
β’ (z - x) * f y < (z - y) * f x + (y - x) * f z | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
| rw [β lt_div_iff' hxz'] | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
| Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
hyz' : 0 < z - y
hxz' : 0 < z - x
β’ f y < ((z - y) * f x + (y - x) * f z) / (z - x) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
| have ha : 0 < (z - y) / (z - x) := by positivity | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
| Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
hyz' : 0 < z - y
hxz' : 0 < z - x
β’ 0 < (z - y) / (z - x) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by | positivity | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by | Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
hyz' : 0 < z - y
hxz' : 0 < z - x
ha : 0 < (z - y) / (z - x)
β’ f y < ((z - y) * f x + (y - x) * f z) / (z - x) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
| have hb : 0 < (y - x) / (z - x) := by positivity | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
| Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
hyz' : 0 < z - y
hxz' : 0 < z - x
ha : 0 < (z - y) / (z - x)
β’ 0 < (y - x) / (z - x) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by | positivity | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by | Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
hyz' : 0 < z - y
hxz' : 0 < z - x
ha : 0 < (z - y) / (z - x)
hb : 0 < (y - x) / (z - x)
β’ f y < ((z - y) * f x + (y - x) * f z) / (z - x) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
| calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
| Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
hyz' : 0 < z - y
hxz' : 0 < z - x
ha : 0 < (z - y) / (z - x)
hb : 0 < (y - x) / (z - x)
β’ x β z | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by | linarith | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by | Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
case calc_1
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
hyz' : 0 < z - y
hxz' : 0 < z - x
ha : 0 < (z - y) / (z - x)
hb : 0 < (y - x) / (z - x)
β’ f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· | congr 1 | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· | Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
case calc_1.e_a
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
hyz' : 0 < z - y
hxz' : 0 < z - x
ha : 0 < (z - y) / (z - x)
hb : 0 < (y - x) / (z - x)
β’ y = (z - y) / (z - x) * x + (y - x) / (z - x) * z | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
| field_simp | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
| Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
case calc_1.e_a
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
hyz' : 0 < z - y
hxz' : 0 < z - x
ha : 0 < (z - y) / (z - x)
hb : 0 < (y - x) / (z - x)
β’ y * (z - x) = (z - y) * x + (y - x) * z | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
| ring | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
| Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
case calc_2
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
hyz' : 0 < z - y
hxz' : 0 < z - x
ha : 0 < (z - y) / (z - x)
hb : 0 < (y - x) / (z - x)
β’ Div.div (z - y) (z - x) + Div.div (y - x) (z - x) = 1 | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
| show (z - y) / (z - x) + (y - x) / (z - x) = 1 | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
| Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
case calc_2
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
hyz' : 0 < z - y
hxz' : 0 < z - x
ha : 0 < (z - y) / (z - x)
hb : 0 < (y - x) / (z - x)
β’ (z - y) / (z - x) + (y - x) / (z - x) = 1 | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
| field_simp | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
| Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
case calc_3
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
hyz' : 0 < z - y
hxz' : 0 < z - x
ha : 0 < (z - y) / (z - x)
hb : 0 < (y - x) / (z - x)
β’ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z = ((z - y) * f x + (y - x) * f z) / (z - x) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· | field_simp | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· | Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
β’ (f y - f x) / (y - x) < (f z - f x) / (z - x) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
| have hxy' : 0 < y - x := by linarith | theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
| Mathlib.Analysis.Convex.Slope.300_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
β’ 0 < y - x | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by | linarith | theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by | Mathlib.Analysis.Convex.Slope.300_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
β’ (f y - f x) / (y - x) < (f z - f x) / (z - x) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
| have hxz' : 0 < z - x := by linarith | theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
| Mathlib.Analysis.Convex.Slope.300_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
β’ 0 < z - x | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by | linarith | theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by | Mathlib.Analysis.Convex.Slope.300_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
hxz' : 0 < z - x
β’ (f y - f x) / (y - x) < (f z - f x) / (z - x) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
| rw [div_lt_div_iff hxy' hxz'] | theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
| Mathlib.Analysis.Convex.Slope.300_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hxy' : 0 < y - x
hxz' : 0 < z - x
β’ (f y - f x) * (z - x) < (f z - f x) * (y - x) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
| linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] | theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
| Mathlib.Analysis.Convex.Slope.300_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
β’ (f z - f x) / (z - x) < (f z - f y) / (z - y) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
| have hyz' : 0 < z - y := by linarith | theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
| Mathlib.Analysis.Convex.Slope.308_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
β’ 0 < z - y | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by | linarith | theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by | Mathlib.Analysis.Convex.Slope.308_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hyz' : 0 < z - y
β’ (f z - f x) / (z - x) < (f z - f y) / (z - y) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
| have hxz' : 0 < z - x := by linarith | theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
| Mathlib.Analysis.Convex.Slope.308_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hyz' : 0 < z - y
β’ 0 < z - x | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by | linarith | theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by | Mathlib.Analysis.Convex.Slope.308_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hyz' : 0 < z - y
hxz' : 0 < z - x
β’ (f z - f x) / (z - x) < (f z - f y) / (z - y) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
| rw [div_lt_div_iff hxz' hyz'] | theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
| Mathlib.Analysis.Convex.Slope.308_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
hyz' : 0 < z - y
hxz' : 0 < z - x
β’ (f z - f x) * (z - y) < (f z - f y) * (z - x) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
| linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] | theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
| Mathlib.Analysis.Convex.Slope.308_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxa : x β a
hya : y β a
hxy : x < y
β’ (f x - f a) / (x - a) < (f y - f a) / (y - a) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
| cases' lt_or_gt_of_ne hxa with hxa hxa | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
| Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) | Mathlib_Analysis_Convex_Slope |
case inl
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxaβ : x β a
hya : y β a
hxy : x < y
hxa : x < a
β’ (f x - f a) / (x - a) < (f y - f a) / (y - a) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· | cases' lt_or_gt_of_ne hya with hya hya | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· | Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) | Mathlib_Analysis_Convex_Slope |
case inl.inl
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxaβ : x β a
hyaβ : y β a
hxy : x < y
hxa : x < a
hya : y < a
β’ (f x - f a) / (x - a) < (f y - f a) / (y - a) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· | convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· | Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) | Mathlib_Analysis_Convex_Slope |
case h.e'_3
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxaβ : x β a
hyaβ : y β a
hxy : x < y
hxa : x < a
hya : y < a
β’ (f x - f a) / (x - a) = (f a - f x) / (a - x) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> | rw [β neg_div_neg_eq] | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> | Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) | Mathlib_Analysis_Convex_Slope |
case h.e'_4
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxaβ : x β a
hyaβ : y β a
hxy : x < y
hxa : x < a
hya : y < a
β’ (f y - f a) / (y - a) = (f a - f y) / (a - y) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> | rw [β neg_div_neg_eq] | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> | Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) | Mathlib_Analysis_Convex_Slope |
case h.e'_3
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxaβ : x β a
hyaβ : y β a
hxy : x < y
hxa : x < a
hya : y < a
β’ -(f x - f a) / -(x - a) = (f a - f x) / (a - x) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
| field_simp | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
| Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) | Mathlib_Analysis_Convex_Slope |
case h.e'_4
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxaβ : x β a
hyaβ : y β a
hxy : x < y
hxa : x < a
hya : y < a
β’ -(f y - f a) / -(y - a) = (f a - f y) / (a - y) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
| field_simp | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
| Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) | Mathlib_Analysis_Convex_Slope |
case inl.inr
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxaβ : x β a
hyaβ : y β a
hxy : x < y
hxa : x < a
hya : y > a
β’ (f x - f a) / (x - a) < (f y - f a) / (y - a) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· | convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· | Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) | Mathlib_Analysis_Convex_Slope |
case h.e'_3
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxaβ : x β a
hyaβ : y β a
hxy : x < y
hxa : x < a
hya : y > a
β’ (f x - f a) / (x - a) = (f a - f x) / (a - x) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
| rw [β neg_div_neg_eq] | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
| Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) | Mathlib_Analysis_Convex_Slope |
case h.e'_3
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxaβ : x β a
hyaβ : y β a
hxy : x < y
hxa : x < a
hya : y > a
β’ -(f x - f a) / -(x - a) = (f a - f x) / (a - x) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; | field_simp | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; | Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) | Mathlib_Analysis_Convex_Slope |
case inr
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxaβ : x β a
hya : y β a
hxy : x < y
hxa : x > a
β’ (f x - f a) / (x - a) < (f y - f a) / (y - a) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· | exact hf.secant_strict_mono_aux2 ha hy hxa hxy | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· | Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ | theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConcaveOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxa : x β a
hya : y β a
hxy : x < y
β’ (f y - f a) / (y - a) < (f x - f a) / (x - a) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
| have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy | theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
| Mathlib.Analysis.Convex.Slope.328_0.2UqTeSfXEWgn9kZ | theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConcaveOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxa : x β a
hya : y β a
hxy : x < y
key : ((-f) x - (-f) a) / (x - a) < ((-f) y - (-f) a) / (y - a)
β’ (f y - f a) / (y - a) < (f x - f a) / (x - a) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
| simp only [Pi.neg_apply] at key | theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
| Mathlib.Analysis.Convex.Slope.328_0.2UqTeSfXEWgn9kZ | theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConcaveOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxa : x β a
hya : y β a
hxy : x < y
key : (-f x - -f a) / (x - a) < (-f y - -f a) / (y - a)
β’ (f y - f a) / (y - a) < (f x - f a) / (x - a) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
| rw [β neg_lt_neg_iff] | theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
| Mathlib.Analysis.Convex.Slope.328_0.2UqTeSfXEWgn9kZ | theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConcaveOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxa : x β a
hya : y β a
hxy : x < y
key : (-f x - -f a) / (x - a) < (-f y - -f a) / (y - a)
β’ -((f x - f a) / (x - a)) < -((f y - f a) / (y - a)) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
| convert key using 1 | theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
| Mathlib.Analysis.Convex.Slope.328_0.2UqTeSfXEWgn9kZ | theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) | Mathlib_Analysis_Convex_Slope |
case h.e'_3
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConcaveOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxa : x β a
hya : y β a
hxy : x < y
key : (-f x - -f a) / (x - a) < (-f y - -f a) / (y - a)
β’ -((f x - f a) / (x - a)) = (-f x - -f a) / (x - a) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> | field_simp | theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> | Mathlib.Analysis.Convex.Slope.328_0.2UqTeSfXEWgn9kZ | theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) | Mathlib_Analysis_Convex_Slope |
case h.e'_4
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConcaveOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxa : x β a
hya : y β a
hxy : x < y
key : (-f x - -f a) / (x - a) < (-f y - -f a) / (y - a)
β’ -((f y - f a) / (y - a)) = (-f y - -f a) / (y - a) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> | field_simp | theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> | Mathlib.Analysis.Convex.Slope.328_0.2UqTeSfXEWgn9kZ | theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) | Mathlib_Analysis_Convex_Slope |
case h.e'_3
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConcaveOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxa : x β a
hya : y β a
hxy : x < y
key : (-f x - -f a) / (x - a) < (-f y - -f a) / (y - a)
β’ (f a - f x) / (x - a) = (-f x + f a) / (x - a) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> | ring | theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> | Mathlib.Analysis.Convex.Slope.328_0.2UqTeSfXEWgn9kZ | theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) | Mathlib_Analysis_Convex_Slope |
case h.e'_4
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConcaveOn π s f
a x y : π
ha : a β s
hx : x β s
hy : y β s
hxa : x β a
hya : y β a
hxy : x < y
key : (-f x - -f a) / (x - a) < (-f y - -f a) / (y - a)
β’ (f a - f y) / (y - a) = (-f y + f a) / (y - a) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> | ring | theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> | Mathlib.Analysis.Convex.Slope.328_0.2UqTeSfXEWgn9kZ | theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
x y : π
hx : x β s
hxy : x < y
hxy' : f x < f y
β’ StrictMonoOn f (s β© Set.Ici y) | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> ring
#align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
| intro u hu v hv huv | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
| Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
x y : π
hx : x β s
hxy : x < y
hxy' : f x < f y
u : π
hu : u β s β© Set.Ici y
v : π
hv : v β s β© Set.Ici y
huv : u < v
β’ f u < f v | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> ring
#align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
| have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact β¨hxy, hz.2β© | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
| Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
x y : π
hx : x β s
hxy : x < y
hxy' : f x < f y
u : π
hu : u β s β© Set.Ici y
v : π
hv : v β s β© Set.Ici y
huv : u < v
β’ β {z : π}, z β s β© Set.Ioi y β f y < f z | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> ring
#align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
| intros z hz | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
| Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
x y : π
hx : x β s
hxy : x < y
hxy' : f x < f y
u : π
hu : u β s β© Set.Ici y
v : π
hv : v β s β© Set.Ici y
huv : u < v
z : π
hz : z β s β© Set.Ioi y
β’ f y < f z | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> ring
#align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
| refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
| Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
x y : π
hx : x β s
hxy : x < y
hxy' : f x < f y
u : π
hu : u β s β© Set.Ici y
v : π
hv : v β s β© Set.Ici y
huv : u < v
z : π
hz : z β s β© Set.Ioi y
β’ y β openSegment π x z | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> ring
#align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
| rw [openSegment_eq_Ioo (hxy.trans hz.2)] | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
| Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
x y : π
hx : x β s
hxy : x < y
hxy' : f x < f y
u : π
hu : u β s β© Set.Ici y
v : π
hv : v β s β© Set.Ici y
huv : u < v
z : π
hz : z β s β© Set.Ioi y
β’ y β Set.Ioo x z | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> ring
#align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
| exact β¨hxy, hz.2β© | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
| Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
x y : π
hx : x β s
hxy : x < y
hxy' : f x < f y
u : π
hu : u β s β© Set.Ici y
v : π
hv : v β s β© Set.Ici y
huv : u < v
step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z
β’ f u < f v | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> ring
#align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact β¨hxy, hz.2β©
| rcases eq_or_lt_of_le hu.2 with (rfl | hu2) | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact β¨hxy, hz.2β©
| Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) | Mathlib_Analysis_Convex_Slope |
case inl
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
x y : π
hx : x β s
hxy : x < y
hxy' : f x < f y
v : π
hv : v β s β© Set.Ici y
step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z
hu : y β s β© Set.Ici y
huv : y < v
β’ f y < f v | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> ring
#align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact β¨hxy, hz.2β©
rcases eq_or_lt_of_le hu.2 with (rfl | hu2)
Β· | exact step1 β¨hv.1, huvβ© | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact β¨hxy, hz.2β©
rcases eq_or_lt_of_le hu.2 with (rfl | hu2)
Β· | Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) | Mathlib_Analysis_Convex_Slope |
case inr
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
x y : π
hx : x β s
hxy : x < y
hxy' : f x < f y
u : π
hu : u β s β© Set.Ici y
v : π
hv : v β s β© Set.Ici y
huv : u < v
step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z
hu2 : y < u
β’ f u < f v | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> ring
#align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact β¨hxy, hz.2β©
rcases eq_or_lt_of_le hu.2 with (rfl | hu2)
Β· exact step1 β¨hv.1, huvβ©
Β· | refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 β¨hu.1, hu2β©) | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact β¨hxy, hz.2β©
rcases eq_or_lt_of_le hu.2 with (rfl | hu2)
Β· exact step1 β¨hv.1, huvβ©
Β· | Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) | Mathlib_Analysis_Convex_Slope |
case inr.refine'_1
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
x y : π
hx : x β s
hxy : x < y
hxy' : f x < f y
u : π
hu : u β s β© Set.Ici y
v : π
hv : v β s β© Set.Ici y
huv : u < v
step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z
hu2 : y < u
β’ y β s | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> ring
#align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact β¨hxy, hz.2β©
rcases eq_or_lt_of_le hu.2 with (rfl | hu2)
Β· exact step1 β¨hv.1, huvβ©
Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 β¨hu.1, hu2β©)
Β· | apply hf.1.segment_subset hx hu.1 | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact β¨hxy, hz.2β©
rcases eq_or_lt_of_le hu.2 with (rfl | hu2)
Β· exact step1 β¨hv.1, huvβ©
Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 β¨hu.1, hu2β©)
Β· | Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) | Mathlib_Analysis_Convex_Slope |
case inr.refine'_1.a
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
x y : π
hx : x β s
hxy : x < y
hxy' : f x < f y
u : π
hu : u β s β© Set.Ici y
v : π
hv : v β s β© Set.Ici y
huv : u < v
step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z
hu2 : y < u
β’ y β segment π x u | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> ring
#align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact β¨hxy, hz.2β©
rcases eq_or_lt_of_le hu.2 with (rfl | hu2)
Β· exact step1 β¨hv.1, huvβ©
Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 β¨hu.1, hu2β©)
Β· apply hf.1.segment_subset hx hu.1
| rw [segment_eq_Icc (hxy.le.trans hu.2)] | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact β¨hxy, hz.2β©
rcases eq_or_lt_of_le hu.2 with (rfl | hu2)
Β· exact step1 β¨hv.1, huvβ©
Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 β¨hu.1, hu2β©)
Β· apply hf.1.segment_subset hx hu.1
| Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) | Mathlib_Analysis_Convex_Slope |
case inr.refine'_1.a
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
x y : π
hx : x β s
hxy : x < y
hxy' : f x < f y
u : π
hu : u β s β© Set.Ici y
v : π
hv : v β s β© Set.Ici y
huv : u < v
step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z
hu2 : y < u
β’ y β Set.Icc x u | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> ring
#align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact β¨hxy, hz.2β©
rcases eq_or_lt_of_le hu.2 with (rfl | hu2)
Β· exact step1 β¨hv.1, huvβ©
Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 β¨hu.1, hu2β©)
Β· apply hf.1.segment_subset hx hu.1
rw [segment_eq_Icc (hxy.le.trans hu.2)]
| exact β¨hxy.le, hu.2β© | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact β¨hxy, hz.2β©
rcases eq_or_lt_of_le hu.2 with (rfl | hu2)
Β· exact step1 β¨hv.1, huvβ©
Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 β¨hu.1, hu2β©)
Β· apply hf.1.segment_subset hx hu.1
rw [segment_eq_Icc (hxy.le.trans hu.2)]
| Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) | Mathlib_Analysis_Convex_Slope |
case inr.refine'_2
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
x y : π
hx : x β s
hxy : x < y
hxy' : f x < f y
u : π
hu : u β s β© Set.Ici y
v : π
hv : v β s β© Set.Ici y
huv : u < v
step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z
hu2 : y < u
β’ u β openSegment π y v | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> ring
#align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact β¨hxy, hz.2β©
rcases eq_or_lt_of_le hu.2 with (rfl | hu2)
Β· exact step1 β¨hv.1, huvβ©
Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 β¨hu.1, hu2β©)
Β· apply hf.1.segment_subset hx hu.1
rw [segment_eq_Icc (hxy.le.trans hu.2)]
exact β¨hxy.le, hu.2β©
Β· | rw [openSegment_eq_Ioo (hu2.trans huv)] | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact β¨hxy, hz.2β©
rcases eq_or_lt_of_le hu.2 with (rfl | hu2)
Β· exact step1 β¨hv.1, huvβ©
Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 β¨hu.1, hu2β©)
Β· apply hf.1.segment_subset hx hu.1
rw [segment_eq_Icc (hxy.le.trans hu.2)]
exact β¨hxy.le, hu.2β©
Β· | Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) | Mathlib_Analysis_Convex_Slope |
case inr.refine'_2
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
x y : π
hx : x β s
hxy : x < y
hxy' : f x < f y
u : π
hu : u β s β© Set.Ici y
v : π
hv : v β s β© Set.Ici y
huv : u < v
step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z
hu2 : y < u
β’ u β Set.Ioo y v | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo JaffrΓ©
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {π : Type*} [LinearOrderedField π] {s : Set π} {f : π β π}
/-- If `f : π β π` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) β€ f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz (show 0 β€ a by apply div_nonneg <;> linarith)
(show 0 β€ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [mul_comm (z - x) _] at key β’
rw [div_le_div_right]
Β· linarith
Β· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : π β π` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) β€ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : π β π` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π s f) {x y z : π}
(hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [β sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this β’
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a β’ x + b β’ z = y := by field_simp; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp)
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key β’
rw [div_lt_div_right]
Β· linarith
Β· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : π β π` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, β neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)) :
ConvexOn π s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', β add_sub_assoc, le_sub_iff_add_le, β mul_add,
sub_add_sub_cancel, β le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)) :
ConcaveOn π s f := by
rw [β neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_le_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn π s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [β one_mul x, β hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [β one_mul z, β hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, β sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, β sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', β hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', β add_sub_assoc, lt_sub_iff_add_lt, β mul_add,
sub_add_sub_cancel, β lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π β π` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π s)
(hf :
β {x y z : π},
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)) :
StrictConcaveOn π s f := by
rw [β neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [β neg_lt_neg_iff]
simp_rw [β neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent
/-- A function `f : π β π` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem convexOn_iff_slope_mono_adjacent :
ConvexOn π s f β
Convex π s β§ β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_mono_adjacentβ©, fun h =>
convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent
/-- A function `f : π β π` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem concaveOn_iff_slope_anti_adjacent :
ConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent
/-- A function `f : π β π` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConvexOn_iff_slope_strict_mono_adjacent :
StrictConvexOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_strict_mono_adjacentβ©, fun h =>
strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent
/-- A function `f : π β π` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem strictConcaveOn_iff_slope_strict_anti_adjacent :
StrictConcaveOn π s f β
Convex π s β§
β β¦x y z : πβ¦,
x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨fun h => β¨h.1, fun _ _ _ => h.slope_anti_adjacentβ©, fun h =>
strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)β©
#align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (z - x) * f y β€ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β le_div_iff' hxz']
have ha : 0 β€ (z - y) / (z - x) := by positivity
have hb : 0 β€ (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ β€ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) β€ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π s f) {x y z : π} (hx : x β s) (hz : z β s)
(hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) β€ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
#align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3
theorem ConvexOn.secant_mono (hf : ConvexOn π s f) {a x y : π} (ha : a β s) (hx : x β s)
(hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x β€ y) :
(f x - f a) / (x - a) β€ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;> field_simp
Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_mono_aux2 ha hy hxa hxy
#align convex_on.secant_mono ConvexOn.secant_mono
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [β lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
calc
f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_
_ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_)
_ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
Β· congr 1
field_simp
ring
Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
Β· field_simp
#align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
#align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
Β· cases' lt_or_gt_of_ne hya with hya hya
Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [β neg_div_neg_eq] <;>
field_simp
Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [β neg_div_neg_eq]; field_simp
Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy
#align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π s f) {a x y : π} (ha : a β s)
(hx : x β s) (hy : y β s) (hxa : x β a) (hya : y β a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
rw [β neg_lt_neg_iff]
convert key using 1 <;> field_simp <;> ring
#align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact β¨hxy, hz.2β©
rcases eq_or_lt_of_le hu.2 with (rfl | hu2)
Β· exact step1 β¨hv.1, huvβ©
Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 β¨hu.1, hu2β©)
Β· apply hf.1.segment_subset hx hu.1
rw [segment_eq_Icc (hxy.le.trans hu.2)]
exact β¨hxy.le, hu.2β©
Β· rw [openSegment_eq_Ioo (hu2.trans huv)]
| exact β¨hu2, huvβ© | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) := by
intro u hu v hv huv
have step1 : β {z : π}, z β s β© Set.Ioi y β f y < f z := by
intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact β¨hxy, hz.2β©
rcases eq_or_lt_of_le hu.2 with (rfl | hu2)
Β· exact step1 β¨hv.1, huvβ©
Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 β¨hu.1, hu2β©)
Β· apply hf.1.segment_subset hx hu.1
rw [segment_eq_Icc (hxy.le.trans hu.2)]
exact β¨hxy.le, hu.2β©
Β· rw [openSegment_eq_Ioo (hu2.trans huv)]
| Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ | /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s β© [y, β)`. -/
theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π s f) {x y : π} (hx : x β s) (hxy : x < y)
(hxy' : f x < f y) : StrictMonoOn f (s β© Set.Ici y) | Mathlib_Analysis_Convex_Slope |
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
s t : Compacts Ξ±
h : s.carrier = t.carrier
β’ s = t | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by | cases s | instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by | Mathlib.Topology.Sets.Compacts.43_0.XVs1udLPbHOIEoW | instance : SetLike (Compacts Ξ±) Ξ± where
coe | Mathlib_Topology_Sets_Compacts |
case mk
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
t : Compacts Ξ±
carrierβ : Set Ξ±
isCompact'β : IsCompact carrierβ
h : { carrier := carrierβ, isCompact' := isCompact'β }.carrier = t.carrier
β’ { carrier := carrierβ, isCompact' := isCompact'β } = t | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; | cases t | instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; | Mathlib.Topology.Sets.Compacts.43_0.XVs1udLPbHOIEoW | instance : SetLike (Compacts Ξ±) Ξ± where
coe | Mathlib_Topology_Sets_Compacts |
case mk.mk
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
carrierβΒΉ : Set Ξ±
isCompact'βΒΉ : IsCompact carrierβΒΉ
carrierβ : Set Ξ±
isCompact'β : IsCompact carrierβ
h :
{ carrier := carrierβΒΉ, isCompact' := isCompact'βΒΉ }.carrier =
{ carrier := carrierβ, isCompact' := isCompact'β }.carrier
β’ { carrier := carrierβΒΉ, isCompact' := isCompact'βΒΉ } = { carrier := carrierβ, isCompact' := isCompact'β } | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; | congr | instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; | Mathlib.Topology.Sets.Compacts.43_0.XVs1udLPbHOIEoW | instance : SetLike (Compacts Ξ±) Ξ± where
coe | Mathlib_Topology_Sets_Compacts |
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
ΞΉ : Type u_4
s : Finset ΞΉ
f : ΞΉ β Compacts Ξ±
β’ β(Finset.sup s f) = Finset.sup s fun i => β(f i) | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
| refine Finset.cons_induction_on s rfl fun a s _ h => ?_ | @[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
| Mathlib.Topology.Sets.Compacts.123_0.XVs1udLPbHOIEoW | @[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) | Mathlib_Topology_Sets_Compacts |
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
ΞΉ : Type u_4
sβ : Finset ΞΉ
f : ΞΉ β Compacts Ξ±
a : ΞΉ
s : Finset ΞΉ
xβ : a β s
h : β(Finset.sup s f) = Finset.sup s fun i => β(f i)
β’ β(Finset.sup (Finset.cons a s xβ) f) = Finset.sup (Finset.cons a s xβ) fun i => β(f i) | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
| simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] | @[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
| Mathlib.Topology.Sets.Compacts.123_0.XVs1udLPbHOIEoW | @[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) | Mathlib_Topology_Sets_Compacts |
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
ΞΉ : Type u_4
sβ : Finset ΞΉ
f : ΞΉ β Compacts Ξ±
a : ΞΉ
s : Finset ΞΉ
xβ : a β s
h : β(Finset.sup s f) = Finset.sup s fun i => β(f i)
β’ β(f a) βͺ β(Finset.sup s f) = β(f a) βͺ Finset.sup s fun i => β(f i) | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
| congr | @[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
| Mathlib.Topology.Sets.Compacts.123_0.XVs1udLPbHOIEoW | @[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) | Mathlib_Topology_Sets_Compacts |
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
f : Ξ± ββ Ξ²
s : Compacts Ξ±
β’ Compacts.map β(Homeomorph.symm f) (_ : Continuous β(Homeomorph.symm f)) (Compacts.map βf (_ : Continuous βf) s) = s | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
| ext1 | /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
| Mathlib.Topology.Sets.Compacts.151_0.XVs1udLPbHOIEoW | /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun | Mathlib_Topology_Sets_Compacts |
case h
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
f : Ξ± ββ Ξ²
s : Compacts Ξ±
β’ β(Compacts.map β(Homeomorph.symm f) (_ : Continuous β(Homeomorph.symm f)) (Compacts.map βf (_ : Continuous βf) s)) =
βs | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
| simp only [coe_map, β image_comp, f.symm_comp_self, image_id] | /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
| Mathlib.Topology.Sets.Compacts.151_0.XVs1udLPbHOIEoW | /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun | Mathlib_Topology_Sets_Compacts |
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
f : Ξ± ββ Ξ²
s : Compacts Ξ²
β’ Compacts.map βf (_ : Continuous βf) (Compacts.map β(Homeomorph.symm f) (_ : Continuous β(Homeomorph.symm f)) s) = s | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
| ext1 | /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
| Mathlib.Topology.Sets.Compacts.151_0.XVs1udLPbHOIEoW | /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun | Mathlib_Topology_Sets_Compacts |
case h
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
f : Ξ± ββ Ξ²
s : Compacts Ξ²
β’ β(Compacts.map βf (_ : Continuous βf) (Compacts.map β(Homeomorph.symm f) (_ : Continuous β(Homeomorph.symm f)) s)) =
βs | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
ext1
| simp only [coe_map, β image_comp, f.self_comp_symm, image_id] | /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
ext1
| Mathlib.Topology.Sets.Compacts.151_0.XVs1udLPbHOIEoW | /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun | Mathlib_Topology_Sets_Compacts |
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
s t : NonemptyCompacts Ξ±
h : (fun s => s.carrier) s = (fun s => s.carrier) t
β’ s = t | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
ext1
simp only [coe_map, β image_comp, f.self_comp_symm, image_id]
#align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv
@[simp]
theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ :=
Equiv.ext map_id
#align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl
@[simp]
theorem equiv_trans (f : Ξ± ββ Ξ²) (g : Ξ² ββ Ξ³) :
Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) :=
-- porting note: can no longer write `map_comp _ _ _ _` and unify
Equiv.ext <| map_comp g f g.continuous f.continuous
#align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans
@[simp]
theorem equiv_symm (f : Ξ± ββ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm :=
rfl
#align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm
/-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/
theorem coe_equiv_apply_eq_preimage (f : Ξ± ββ Ξ²) (K : Compacts Ξ±) :
(Compacts.equiv f K : Set Ξ²) = f.symm β»ΒΉ' (K : Set Ξ±) :=
f.toEquiv.image_eq_preimage K
#align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage
/-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product
space. -/
protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ Ξ²) where
carrier := K ΓΛ’ L
isCompact' := IsCompact.prod K.2 L.2
#align topological_space.compacts.prod TopologicalSpace.Compacts.prod
@[simp]
theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod
-- todo: add `pi`
end Compacts
/-! ### Nonempty compact sets -/
/-- The type of nonempty compact sets of a topological space. -/
structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
nonempty' : carrier.Nonempty
#align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts
namespace NonemptyCompacts
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
| obtain β¨β¨_, _β©, _β© := s | instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
| Mathlib.Topology.Sets.Compacts.213_0.XVs1udLPbHOIEoW | instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s | Mathlib_Topology_Sets_Compacts |
case mk.mk
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
t : NonemptyCompacts Ξ±
carrierβ : Set Ξ±
isCompact'β : IsCompact carrierβ
nonempty'β : Set.Nonempty { carrier := carrierβ, isCompact' := isCompact'β }.carrier
h :
(fun s => s.carrier) { toCompacts := { carrier := carrierβ, isCompact' := isCompact'β }, nonempty' := nonempty'β } =
(fun s => s.carrier) t
β’ { toCompacts := { carrier := carrierβ, isCompact' := isCompact'β }, nonempty' := nonempty'β } = t | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
ext1
simp only [coe_map, β image_comp, f.self_comp_symm, image_id]
#align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv
@[simp]
theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ :=
Equiv.ext map_id
#align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl
@[simp]
theorem equiv_trans (f : Ξ± ββ Ξ²) (g : Ξ² ββ Ξ³) :
Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) :=
-- porting note: can no longer write `map_comp _ _ _ _` and unify
Equiv.ext <| map_comp g f g.continuous f.continuous
#align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans
@[simp]
theorem equiv_symm (f : Ξ± ββ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm :=
rfl
#align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm
/-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/
theorem coe_equiv_apply_eq_preimage (f : Ξ± ββ Ξ²) (K : Compacts Ξ±) :
(Compacts.equiv f K : Set Ξ²) = f.symm β»ΒΉ' (K : Set Ξ±) :=
f.toEquiv.image_eq_preimage K
#align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage
/-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product
space. -/
protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ Ξ²) where
carrier := K ΓΛ’ L
isCompact' := IsCompact.prod K.2 L.2
#align topological_space.compacts.prod TopologicalSpace.Compacts.prod
@[simp]
theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod
-- todo: add `pi`
end Compacts
/-! ### Nonempty compact sets -/
/-- The type of nonempty compact sets of a topological space. -/
structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
nonempty' : carrier.Nonempty
#align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts
namespace NonemptyCompacts
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
| obtain β¨β¨_, _β©, _β© := t | instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
| Mathlib.Topology.Sets.Compacts.213_0.XVs1udLPbHOIEoW | instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s | Mathlib_Topology_Sets_Compacts |
case mk.mk.mk.mk
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
carrierβΒΉ : Set Ξ±
isCompact'βΒΉ : IsCompact carrierβΒΉ
nonempty'βΒΉ : Set.Nonempty { carrier := carrierβΒΉ, isCompact' := isCompact'βΒΉ }.carrier
carrierβ : Set Ξ±
isCompact'β : IsCompact carrierβ
nonempty'β : Set.Nonempty { carrier := carrierβ, isCompact' := isCompact'β }.carrier
h :
(fun s => s.carrier)
{ toCompacts := { carrier := carrierβΒΉ, isCompact' := isCompact'βΒΉ }, nonempty' := nonempty'βΒΉ } =
(fun s => s.carrier) { toCompacts := { carrier := carrierβ, isCompact' := isCompact'β }, nonempty' := nonempty'β }
β’ { toCompacts := { carrier := carrierβΒΉ, isCompact' := isCompact'βΒΉ }, nonempty' := nonempty'βΒΉ } =
{ toCompacts := { carrier := carrierβ, isCompact' := isCompact'β }, nonempty' := nonempty'β } | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
ext1
simp only [coe_map, β image_comp, f.self_comp_symm, image_id]
#align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv
@[simp]
theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ :=
Equiv.ext map_id
#align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl
@[simp]
theorem equiv_trans (f : Ξ± ββ Ξ²) (g : Ξ² ββ Ξ³) :
Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) :=
-- porting note: can no longer write `map_comp _ _ _ _` and unify
Equiv.ext <| map_comp g f g.continuous f.continuous
#align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans
@[simp]
theorem equiv_symm (f : Ξ± ββ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm :=
rfl
#align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm
/-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/
theorem coe_equiv_apply_eq_preimage (f : Ξ± ββ Ξ²) (K : Compacts Ξ±) :
(Compacts.equiv f K : Set Ξ²) = f.symm β»ΒΉ' (K : Set Ξ±) :=
f.toEquiv.image_eq_preimage K
#align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage
/-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product
space. -/
protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ Ξ²) where
carrier := K ΓΛ’ L
isCompact' := IsCompact.prod K.2 L.2
#align topological_space.compacts.prod TopologicalSpace.Compacts.prod
@[simp]
theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod
-- todo: add `pi`
end Compacts
/-! ### Nonempty compact sets -/
/-- The type of nonempty compact sets of a topological space. -/
structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
nonempty' : carrier.Nonempty
#align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts
namespace NonemptyCompacts
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
| congr | instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
| Mathlib.Topology.Sets.Compacts.213_0.XVs1udLPbHOIEoW | instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s | Mathlib_Topology_Sets_Compacts |
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
s t : PositiveCompacts Ξ±
h : (fun s => s.carrier) s = (fun s => s.carrier) t
β’ s = t | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
ext1
simp only [coe_map, β image_comp, f.self_comp_symm, image_id]
#align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv
@[simp]
theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ :=
Equiv.ext map_id
#align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl
@[simp]
theorem equiv_trans (f : Ξ± ββ Ξ²) (g : Ξ² ββ Ξ³) :
Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) :=
-- porting note: can no longer write `map_comp _ _ _ _` and unify
Equiv.ext <| map_comp g f g.continuous f.continuous
#align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans
@[simp]
theorem equiv_symm (f : Ξ± ββ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm :=
rfl
#align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm
/-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/
theorem coe_equiv_apply_eq_preimage (f : Ξ± ββ Ξ²) (K : Compacts Ξ±) :
(Compacts.equiv f K : Set Ξ²) = f.symm β»ΒΉ' (K : Set Ξ±) :=
f.toEquiv.image_eq_preimage K
#align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage
/-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product
space. -/
protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ Ξ²) where
carrier := K ΓΛ’ L
isCompact' := IsCompact.prod K.2 L.2
#align topological_space.compacts.prod TopologicalSpace.Compacts.prod
@[simp]
theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod
-- todo: add `pi`
end Compacts
/-! ### Nonempty compact sets -/
/-- The type of nonempty compact sets of a topological space. -/
structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
nonempty' : carrier.Nonempty
#align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts
namespace NonemptyCompacts
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections NonemptyCompacts (carrier β coe)
protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact
protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.nonempty'
#align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty
/-- Reinterpret a nonempty compact as a closed set. -/
def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± :=
β¨s, s.isCompact.isClosedβ©
#align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds
@[ext]
protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk
-- porting note: `@[simp]` moved to `coe_toCompacts`
theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe
@[simp] -- porting note: new lemma
theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl
instance : Sup (NonemptyCompacts Ξ±) :=
β¨fun s t => β¨s.toCompacts β t.toCompacts, s.nonempty.mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) :=
β¨β¨β€, univ_nonemptyβ©β©
instance : SemilatticeSup (NonemptyCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : NonemptyCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : NonemptyCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top
/-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with
default element the singleton set containing the default element. -/
instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) :=
β¨{ carrier := {default}
isCompact' := isCompact_singleton
nonempty' := singleton_nonempty _ }β©
instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s :=
isCompact_iff_compactSpace.1 s.isCompact
#align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace
instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s :=
s.nonempty.to_subtype
#align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty
/-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts`
in the product space. -/
protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ Ξ²) :=
{ K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty }
#align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod
@[simp]
theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod
end NonemptyCompacts
/-! ### Positive compact sets -/
/-- The type of compact sets with nonempty interior of a topological space.
See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/
structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
interior_nonempty' : (interior carrier).Nonempty
#align topological_space.positive_compacts TopologicalSpace.PositiveCompacts
namespace PositiveCompacts
instance : SetLike (PositiveCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
| obtain β¨β¨_, _β©, _β© := s | instance : SetLike (PositiveCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
| Mathlib.Topology.Sets.Compacts.317_0.XVs1udLPbHOIEoW | instance : SetLike (PositiveCompacts Ξ±) Ξ± where
coe s | Mathlib_Topology_Sets_Compacts |
case mk.mk
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
t : PositiveCompacts Ξ±
carrierβ : Set Ξ±
isCompact'β : IsCompact carrierβ
interior_nonempty'β : Set.Nonempty (interior { carrier := carrierβ, isCompact' := isCompact'β }.carrier)
h :
(fun s => s.carrier)
{ toCompacts := { carrier := carrierβ, isCompact' := isCompact'β }, interior_nonempty' := interior_nonempty'β } =
(fun s => s.carrier) t
β’ { toCompacts := { carrier := carrierβ, isCompact' := isCompact'β }, interior_nonempty' := interior_nonempty'β } = t | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
ext1
simp only [coe_map, β image_comp, f.self_comp_symm, image_id]
#align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv
@[simp]
theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ :=
Equiv.ext map_id
#align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl
@[simp]
theorem equiv_trans (f : Ξ± ββ Ξ²) (g : Ξ² ββ Ξ³) :
Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) :=
-- porting note: can no longer write `map_comp _ _ _ _` and unify
Equiv.ext <| map_comp g f g.continuous f.continuous
#align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans
@[simp]
theorem equiv_symm (f : Ξ± ββ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm :=
rfl
#align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm
/-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/
theorem coe_equiv_apply_eq_preimage (f : Ξ± ββ Ξ²) (K : Compacts Ξ±) :
(Compacts.equiv f K : Set Ξ²) = f.symm β»ΒΉ' (K : Set Ξ±) :=
f.toEquiv.image_eq_preimage K
#align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage
/-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product
space. -/
protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ Ξ²) where
carrier := K ΓΛ’ L
isCompact' := IsCompact.prod K.2 L.2
#align topological_space.compacts.prod TopologicalSpace.Compacts.prod
@[simp]
theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod
-- todo: add `pi`
end Compacts
/-! ### Nonempty compact sets -/
/-- The type of nonempty compact sets of a topological space. -/
structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
nonempty' : carrier.Nonempty
#align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts
namespace NonemptyCompacts
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections NonemptyCompacts (carrier β coe)
protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact
protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.nonempty'
#align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty
/-- Reinterpret a nonempty compact as a closed set. -/
def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± :=
β¨s, s.isCompact.isClosedβ©
#align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds
@[ext]
protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk
-- porting note: `@[simp]` moved to `coe_toCompacts`
theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe
@[simp] -- porting note: new lemma
theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl
instance : Sup (NonemptyCompacts Ξ±) :=
β¨fun s t => β¨s.toCompacts β t.toCompacts, s.nonempty.mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) :=
β¨β¨β€, univ_nonemptyβ©β©
instance : SemilatticeSup (NonemptyCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : NonemptyCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : NonemptyCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top
/-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with
default element the singleton set containing the default element. -/
instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) :=
β¨{ carrier := {default}
isCompact' := isCompact_singleton
nonempty' := singleton_nonempty _ }β©
instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s :=
isCompact_iff_compactSpace.1 s.isCompact
#align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace
instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s :=
s.nonempty.to_subtype
#align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty
/-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts`
in the product space. -/
protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ Ξ²) :=
{ K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty }
#align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod
@[simp]
theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod
end NonemptyCompacts
/-! ### Positive compact sets -/
/-- The type of compact sets with nonempty interior of a topological space.
See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/
structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
interior_nonempty' : (interior carrier).Nonempty
#align topological_space.positive_compacts TopologicalSpace.PositiveCompacts
namespace PositiveCompacts
instance : SetLike (PositiveCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
| obtain β¨β¨_, _β©, _β© := t | instance : SetLike (PositiveCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
| Mathlib.Topology.Sets.Compacts.317_0.XVs1udLPbHOIEoW | instance : SetLike (PositiveCompacts Ξ±) Ξ± where
coe s | Mathlib_Topology_Sets_Compacts |
case mk.mk.mk.mk
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
carrierβΒΉ : Set Ξ±
isCompact'βΒΉ : IsCompact carrierβΒΉ
interior_nonempty'βΒΉ : Set.Nonempty (interior { carrier := carrierβΒΉ, isCompact' := isCompact'βΒΉ }.carrier)
carrierβ : Set Ξ±
isCompact'β : IsCompact carrierβ
interior_nonempty'β : Set.Nonempty (interior { carrier := carrierβ, isCompact' := isCompact'β }.carrier)
h :
(fun s => s.carrier)
{ toCompacts := { carrier := carrierβΒΉ, isCompact' := isCompact'βΒΉ },
interior_nonempty' := interior_nonempty'βΒΉ } =
(fun s => s.carrier)
{ toCompacts := { carrier := carrierβ, isCompact' := isCompact'β }, interior_nonempty' := interior_nonempty'β }
β’ { toCompacts := { carrier := carrierβΒΉ, isCompact' := isCompact'βΒΉ }, interior_nonempty' := interior_nonempty'βΒΉ } =
{ toCompacts := { carrier := carrierβ, isCompact' := isCompact'β }, interior_nonempty' := interior_nonempty'β } | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
ext1
simp only [coe_map, β image_comp, f.self_comp_symm, image_id]
#align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv
@[simp]
theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ :=
Equiv.ext map_id
#align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl
@[simp]
theorem equiv_trans (f : Ξ± ββ Ξ²) (g : Ξ² ββ Ξ³) :
Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) :=
-- porting note: can no longer write `map_comp _ _ _ _` and unify
Equiv.ext <| map_comp g f g.continuous f.continuous
#align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans
@[simp]
theorem equiv_symm (f : Ξ± ββ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm :=
rfl
#align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm
/-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/
theorem coe_equiv_apply_eq_preimage (f : Ξ± ββ Ξ²) (K : Compacts Ξ±) :
(Compacts.equiv f K : Set Ξ²) = f.symm β»ΒΉ' (K : Set Ξ±) :=
f.toEquiv.image_eq_preimage K
#align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage
/-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product
space. -/
protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ Ξ²) where
carrier := K ΓΛ’ L
isCompact' := IsCompact.prod K.2 L.2
#align topological_space.compacts.prod TopologicalSpace.Compacts.prod
@[simp]
theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod
-- todo: add `pi`
end Compacts
/-! ### Nonempty compact sets -/
/-- The type of nonempty compact sets of a topological space. -/
structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
nonempty' : carrier.Nonempty
#align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts
namespace NonemptyCompacts
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections NonemptyCompacts (carrier β coe)
protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact
protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.nonempty'
#align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty
/-- Reinterpret a nonempty compact as a closed set. -/
def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± :=
β¨s, s.isCompact.isClosedβ©
#align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds
@[ext]
protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk
-- porting note: `@[simp]` moved to `coe_toCompacts`
theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe
@[simp] -- porting note: new lemma
theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl
instance : Sup (NonemptyCompacts Ξ±) :=
β¨fun s t => β¨s.toCompacts β t.toCompacts, s.nonempty.mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) :=
β¨β¨β€, univ_nonemptyβ©β©
instance : SemilatticeSup (NonemptyCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : NonemptyCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : NonemptyCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top
/-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with
default element the singleton set containing the default element. -/
instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) :=
β¨{ carrier := {default}
isCompact' := isCompact_singleton
nonempty' := singleton_nonempty _ }β©
instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s :=
isCompact_iff_compactSpace.1 s.isCompact
#align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace
instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s :=
s.nonempty.to_subtype
#align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty
/-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts`
in the product space. -/
protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ Ξ²) :=
{ K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty }
#align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod
@[simp]
theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod
end NonemptyCompacts
/-! ### Positive compact sets -/
/-- The type of compact sets with nonempty interior of a topological space.
See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/
structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
interior_nonempty' : (interior carrier).Nonempty
#align topological_space.positive_compacts TopologicalSpace.PositiveCompacts
namespace PositiveCompacts
instance : SetLike (PositiveCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
| congr | instance : SetLike (PositiveCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
| Mathlib.Topology.Sets.Compacts.317_0.XVs1udLPbHOIEoW | instance : SetLike (PositiveCompacts Ξ±) Ξ± where
coe s | Mathlib_Topology_Sets_Compacts |
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instββ΄ : TopologicalSpace Ξ±
instβΒ³ : TopologicalSpace Ξ²
instβΒ² : TopologicalSpace Ξ³
instβΒΉ : WeaklyLocallyCompactSpace Ξ±
instβ : Nonempty Ξ±
β’ Nonempty (PositiveCompacts Ξ±) | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
ext1
simp only [coe_map, β image_comp, f.self_comp_symm, image_id]
#align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv
@[simp]
theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ :=
Equiv.ext map_id
#align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl
@[simp]
theorem equiv_trans (f : Ξ± ββ Ξ²) (g : Ξ² ββ Ξ³) :
Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) :=
-- porting note: can no longer write `map_comp _ _ _ _` and unify
Equiv.ext <| map_comp g f g.continuous f.continuous
#align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans
@[simp]
theorem equiv_symm (f : Ξ± ββ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm :=
rfl
#align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm
/-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/
theorem coe_equiv_apply_eq_preimage (f : Ξ± ββ Ξ²) (K : Compacts Ξ±) :
(Compacts.equiv f K : Set Ξ²) = f.symm β»ΒΉ' (K : Set Ξ±) :=
f.toEquiv.image_eq_preimage K
#align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage
/-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product
space. -/
protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ Ξ²) where
carrier := K ΓΛ’ L
isCompact' := IsCompact.prod K.2 L.2
#align topological_space.compacts.prod TopologicalSpace.Compacts.prod
@[simp]
theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod
-- todo: add `pi`
end Compacts
/-! ### Nonempty compact sets -/
/-- The type of nonempty compact sets of a topological space. -/
structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
nonempty' : carrier.Nonempty
#align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts
namespace NonemptyCompacts
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections NonemptyCompacts (carrier β coe)
protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact
protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.nonempty'
#align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty
/-- Reinterpret a nonempty compact as a closed set. -/
def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± :=
β¨s, s.isCompact.isClosedβ©
#align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds
@[ext]
protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk
-- porting note: `@[simp]` moved to `coe_toCompacts`
theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe
@[simp] -- porting note: new lemma
theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl
instance : Sup (NonemptyCompacts Ξ±) :=
β¨fun s t => β¨s.toCompacts β t.toCompacts, s.nonempty.mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) :=
β¨β¨β€, univ_nonemptyβ©β©
instance : SemilatticeSup (NonemptyCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : NonemptyCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : NonemptyCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top
/-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with
default element the singleton set containing the default element. -/
instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) :=
β¨{ carrier := {default}
isCompact' := isCompact_singleton
nonempty' := singleton_nonempty _ }β©
instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s :=
isCompact_iff_compactSpace.1 s.isCompact
#align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace
instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s :=
s.nonempty.to_subtype
#align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty
/-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts`
in the product space. -/
protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ Ξ²) :=
{ K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty }
#align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod
@[simp]
theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod
end NonemptyCompacts
/-! ### Positive compact sets -/
/-- The type of compact sets with nonempty interior of a topological space.
See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/
structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
interior_nonempty' : (interior carrier).Nonempty
#align topological_space.positive_compacts TopologicalSpace.PositiveCompacts
namespace PositiveCompacts
instance : SetLike (PositiveCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : PositiveCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections PositiveCompacts (carrier β coe)
protected theorem isCompact (s : PositiveCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.positive_compacts.is_compact TopologicalSpace.PositiveCompacts.isCompact
theorem interior_nonempty (s : PositiveCompacts Ξ±) : (interior (s : Set Ξ±)).Nonempty :=
s.interior_nonempty'
#align topological_space.positive_compacts.interior_nonempty TopologicalSpace.PositiveCompacts.interior_nonempty
protected theorem nonempty (s : PositiveCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.interior_nonempty.mono interior_subset
#align topological_space.positive_compacts.nonempty TopologicalSpace.PositiveCompacts.nonempty
/-- Reinterpret a positive compact as a nonempty compact. -/
def toNonemptyCompacts (s : PositiveCompacts Ξ±) : NonemptyCompacts Ξ± :=
β¨s.toCompacts, s.nonemptyβ©
#align topological_space.positive_compacts.to_nonempty_compacts TopologicalSpace.PositiveCompacts.toNonemptyCompacts
@[ext]
protected theorem ext {s t : PositiveCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.positive_compacts.ext TopologicalSpace.PositiveCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.positive_compacts.coe_mk TopologicalSpace.PositiveCompacts.coe_mk
-- porting note: `@[simp]` moved to a new lemma
theorem carrier_eq_coe (s : PositiveCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.positive_compacts.carrier_eq_coe TopologicalSpace.PositiveCompacts.carrier_eq_coe
@[simp]
theorem coe_toCompacts (s : PositiveCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s :=
rfl
instance : Sup (PositiveCompacts Ξ±) :=
β¨fun s t =>
β¨s.toCompacts β t.toCompacts,
s.interior_nonempty.mono <| interior_mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (PositiveCompacts Ξ±) :=
β¨β¨β€, interior_univ.symm.subst univ_nonemptyβ©β©
instance : SemilatticeSup (PositiveCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (PositiveCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : PositiveCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : PositiveCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.positive_compacts.coe_top TopologicalSpace.PositiveCompacts.coe_top
/-- The image of a positive compact set under a continuous open map. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (hf' : IsOpenMap f) (K : PositiveCompacts Ξ±) :
PositiveCompacts Ξ² :=
{ Compacts.map f hf K.toCompacts with
interior_nonempty' :=
(K.interior_nonempty'.image _).mono (hf'.image_interior_subset K.toCompacts) }
#align topological_space.positive_compacts.map TopologicalSpace.PositiveCompacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (hf' : IsOpenMap f) (s : PositiveCompacts Ξ±) :
(s.map f hf hf' : Set Ξ²) = f '' s :=
rfl
#align topological_space.positive_compacts.coe_map TopologicalSpace.PositiveCompacts.coe_map
@[simp]
theorem map_id (K : PositiveCompacts Ξ±) : K.map id continuous_id IsOpenMap.id = K :=
PositiveCompacts.ext <| Set.image_id _
#align topological_space.positive_compacts.map_id TopologicalSpace.PositiveCompacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f)
(hg' : IsOpenMap g) (K : PositiveCompacts Ξ±) :
K.map (f β g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' :=
PositiveCompacts.ext <| Set.image_comp _ _ _
#align topological_space.positive_compacts.map_comp TopologicalSpace.PositiveCompacts.map_comp
theorem _root_.exists_positiveCompacts_subset [LocallyCompactSpace Ξ±] {U : Set Ξ±} (ho : IsOpen U)
(hn : U.Nonempty) : β K : PositiveCompacts Ξ±, βK β U :=
let β¨x, hxβ© := hn
let β¨K, hKc, hxK, hKUβ© := exists_compact_subset ho hx
β¨β¨β¨K, hKcβ©, β¨x, hxKβ©β©, hKUβ©
#align exists_positive_compacts_subset exists_positiveCompacts_subset
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Inhabited (PositiveCompacts Ξ±) :=
β¨β€β©
/-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/
instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by
| inhabit Ξ± | /-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/
instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by
| Mathlib.Topology.Sets.Compacts.424_0.XVs1udLPbHOIEoW | /-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/
instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) | Mathlib_Topology_Sets_Compacts |
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instββ΄ : TopologicalSpace Ξ±
instβΒ³ : TopologicalSpace Ξ²
instβΒ² : TopologicalSpace Ξ³
instβΒΉ : WeaklyLocallyCompactSpace Ξ±
instβ : Nonempty Ξ±
inhabited_h : Inhabited Ξ±
β’ Nonempty (PositiveCompacts Ξ±) | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
ext1
simp only [coe_map, β image_comp, f.self_comp_symm, image_id]
#align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv
@[simp]
theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ :=
Equiv.ext map_id
#align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl
@[simp]
theorem equiv_trans (f : Ξ± ββ Ξ²) (g : Ξ² ββ Ξ³) :
Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) :=
-- porting note: can no longer write `map_comp _ _ _ _` and unify
Equiv.ext <| map_comp g f g.continuous f.continuous
#align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans
@[simp]
theorem equiv_symm (f : Ξ± ββ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm :=
rfl
#align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm
/-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/
theorem coe_equiv_apply_eq_preimage (f : Ξ± ββ Ξ²) (K : Compacts Ξ±) :
(Compacts.equiv f K : Set Ξ²) = f.symm β»ΒΉ' (K : Set Ξ±) :=
f.toEquiv.image_eq_preimage K
#align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage
/-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product
space. -/
protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ Ξ²) where
carrier := K ΓΛ’ L
isCompact' := IsCompact.prod K.2 L.2
#align topological_space.compacts.prod TopologicalSpace.Compacts.prod
@[simp]
theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod
-- todo: add `pi`
end Compacts
/-! ### Nonempty compact sets -/
/-- The type of nonempty compact sets of a topological space. -/
structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
nonempty' : carrier.Nonempty
#align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts
namespace NonemptyCompacts
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections NonemptyCompacts (carrier β coe)
protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact
protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.nonempty'
#align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty
/-- Reinterpret a nonempty compact as a closed set. -/
def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± :=
β¨s, s.isCompact.isClosedβ©
#align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds
@[ext]
protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk
-- porting note: `@[simp]` moved to `coe_toCompacts`
theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe
@[simp] -- porting note: new lemma
theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl
instance : Sup (NonemptyCompacts Ξ±) :=
β¨fun s t => β¨s.toCompacts β t.toCompacts, s.nonempty.mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) :=
β¨β¨β€, univ_nonemptyβ©β©
instance : SemilatticeSup (NonemptyCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : NonemptyCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : NonemptyCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top
/-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with
default element the singleton set containing the default element. -/
instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) :=
β¨{ carrier := {default}
isCompact' := isCompact_singleton
nonempty' := singleton_nonempty _ }β©
instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s :=
isCompact_iff_compactSpace.1 s.isCompact
#align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace
instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s :=
s.nonempty.to_subtype
#align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty
/-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts`
in the product space. -/
protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ Ξ²) :=
{ K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty }
#align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod
@[simp]
theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod
end NonemptyCompacts
/-! ### Positive compact sets -/
/-- The type of compact sets with nonempty interior of a topological space.
See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/
structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
interior_nonempty' : (interior carrier).Nonempty
#align topological_space.positive_compacts TopologicalSpace.PositiveCompacts
namespace PositiveCompacts
instance : SetLike (PositiveCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : PositiveCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections PositiveCompacts (carrier β coe)
protected theorem isCompact (s : PositiveCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.positive_compacts.is_compact TopologicalSpace.PositiveCompacts.isCompact
theorem interior_nonempty (s : PositiveCompacts Ξ±) : (interior (s : Set Ξ±)).Nonempty :=
s.interior_nonempty'
#align topological_space.positive_compacts.interior_nonempty TopologicalSpace.PositiveCompacts.interior_nonempty
protected theorem nonempty (s : PositiveCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.interior_nonempty.mono interior_subset
#align topological_space.positive_compacts.nonempty TopologicalSpace.PositiveCompacts.nonempty
/-- Reinterpret a positive compact as a nonempty compact. -/
def toNonemptyCompacts (s : PositiveCompacts Ξ±) : NonemptyCompacts Ξ± :=
β¨s.toCompacts, s.nonemptyβ©
#align topological_space.positive_compacts.to_nonempty_compacts TopologicalSpace.PositiveCompacts.toNonemptyCompacts
@[ext]
protected theorem ext {s t : PositiveCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.positive_compacts.ext TopologicalSpace.PositiveCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.positive_compacts.coe_mk TopologicalSpace.PositiveCompacts.coe_mk
-- porting note: `@[simp]` moved to a new lemma
theorem carrier_eq_coe (s : PositiveCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.positive_compacts.carrier_eq_coe TopologicalSpace.PositiveCompacts.carrier_eq_coe
@[simp]
theorem coe_toCompacts (s : PositiveCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s :=
rfl
instance : Sup (PositiveCompacts Ξ±) :=
β¨fun s t =>
β¨s.toCompacts β t.toCompacts,
s.interior_nonempty.mono <| interior_mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (PositiveCompacts Ξ±) :=
β¨β¨β€, interior_univ.symm.subst univ_nonemptyβ©β©
instance : SemilatticeSup (PositiveCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (PositiveCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : PositiveCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : PositiveCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.positive_compacts.coe_top TopologicalSpace.PositiveCompacts.coe_top
/-- The image of a positive compact set under a continuous open map. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (hf' : IsOpenMap f) (K : PositiveCompacts Ξ±) :
PositiveCompacts Ξ² :=
{ Compacts.map f hf K.toCompacts with
interior_nonempty' :=
(K.interior_nonempty'.image _).mono (hf'.image_interior_subset K.toCompacts) }
#align topological_space.positive_compacts.map TopologicalSpace.PositiveCompacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (hf' : IsOpenMap f) (s : PositiveCompacts Ξ±) :
(s.map f hf hf' : Set Ξ²) = f '' s :=
rfl
#align topological_space.positive_compacts.coe_map TopologicalSpace.PositiveCompacts.coe_map
@[simp]
theorem map_id (K : PositiveCompacts Ξ±) : K.map id continuous_id IsOpenMap.id = K :=
PositiveCompacts.ext <| Set.image_id _
#align topological_space.positive_compacts.map_id TopologicalSpace.PositiveCompacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f)
(hg' : IsOpenMap g) (K : PositiveCompacts Ξ±) :
K.map (f β g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' :=
PositiveCompacts.ext <| Set.image_comp _ _ _
#align topological_space.positive_compacts.map_comp TopologicalSpace.PositiveCompacts.map_comp
theorem _root_.exists_positiveCompacts_subset [LocallyCompactSpace Ξ±] {U : Set Ξ±} (ho : IsOpen U)
(hn : U.Nonempty) : β K : PositiveCompacts Ξ±, βK β U :=
let β¨x, hxβ© := hn
let β¨K, hKc, hxK, hKUβ© := exists_compact_subset ho hx
β¨β¨β¨K, hKcβ©, β¨x, hxKβ©β©, hKUβ©
#align exists_positive_compacts_subset exists_positiveCompacts_subset
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Inhabited (PositiveCompacts Ξ±) :=
β¨β€β©
/-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/
instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by
inhabit Ξ±
| rcases exists_compact_mem_nhds (default : Ξ±) with β¨K, hKc, hKβ© | /-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/
instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by
inhabit Ξ±
| Mathlib.Topology.Sets.Compacts.424_0.XVs1udLPbHOIEoW | /-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/
instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) | Mathlib_Topology_Sets_Compacts |
case intro.intro
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instββ΄ : TopologicalSpace Ξ±
instβΒ³ : TopologicalSpace Ξ²
instβΒ² : TopologicalSpace Ξ³
instβΒΉ : WeaklyLocallyCompactSpace Ξ±
instβ : Nonempty Ξ±
inhabited_h : Inhabited Ξ±
K : Set Ξ±
hKc : IsCompact K
hK : K β nhds default
β’ Nonempty (PositiveCompacts Ξ±) | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
ext1
simp only [coe_map, β image_comp, f.self_comp_symm, image_id]
#align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv
@[simp]
theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ :=
Equiv.ext map_id
#align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl
@[simp]
theorem equiv_trans (f : Ξ± ββ Ξ²) (g : Ξ² ββ Ξ³) :
Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) :=
-- porting note: can no longer write `map_comp _ _ _ _` and unify
Equiv.ext <| map_comp g f g.continuous f.continuous
#align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans
@[simp]
theorem equiv_symm (f : Ξ± ββ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm :=
rfl
#align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm
/-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/
theorem coe_equiv_apply_eq_preimage (f : Ξ± ββ Ξ²) (K : Compacts Ξ±) :
(Compacts.equiv f K : Set Ξ²) = f.symm β»ΒΉ' (K : Set Ξ±) :=
f.toEquiv.image_eq_preimage K
#align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage
/-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product
space. -/
protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ Ξ²) where
carrier := K ΓΛ’ L
isCompact' := IsCompact.prod K.2 L.2
#align topological_space.compacts.prod TopologicalSpace.Compacts.prod
@[simp]
theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod
-- todo: add `pi`
end Compacts
/-! ### Nonempty compact sets -/
/-- The type of nonempty compact sets of a topological space. -/
structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
nonempty' : carrier.Nonempty
#align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts
namespace NonemptyCompacts
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections NonemptyCompacts (carrier β coe)
protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact
protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.nonempty'
#align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty
/-- Reinterpret a nonempty compact as a closed set. -/
def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± :=
β¨s, s.isCompact.isClosedβ©
#align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds
@[ext]
protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk
-- porting note: `@[simp]` moved to `coe_toCompacts`
theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe
@[simp] -- porting note: new lemma
theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl
instance : Sup (NonemptyCompacts Ξ±) :=
β¨fun s t => β¨s.toCompacts β t.toCompacts, s.nonempty.mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) :=
β¨β¨β€, univ_nonemptyβ©β©
instance : SemilatticeSup (NonemptyCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : NonemptyCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : NonemptyCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top
/-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with
default element the singleton set containing the default element. -/
instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) :=
β¨{ carrier := {default}
isCompact' := isCompact_singleton
nonempty' := singleton_nonempty _ }β©
instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s :=
isCompact_iff_compactSpace.1 s.isCompact
#align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace
instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s :=
s.nonempty.to_subtype
#align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty
/-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts`
in the product space. -/
protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ Ξ²) :=
{ K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty }
#align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod
@[simp]
theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod
end NonemptyCompacts
/-! ### Positive compact sets -/
/-- The type of compact sets with nonempty interior of a topological space.
See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/
structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
interior_nonempty' : (interior carrier).Nonempty
#align topological_space.positive_compacts TopologicalSpace.PositiveCompacts
namespace PositiveCompacts
instance : SetLike (PositiveCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : PositiveCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections PositiveCompacts (carrier β coe)
protected theorem isCompact (s : PositiveCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.positive_compacts.is_compact TopologicalSpace.PositiveCompacts.isCompact
theorem interior_nonempty (s : PositiveCompacts Ξ±) : (interior (s : Set Ξ±)).Nonempty :=
s.interior_nonempty'
#align topological_space.positive_compacts.interior_nonempty TopologicalSpace.PositiveCompacts.interior_nonempty
protected theorem nonempty (s : PositiveCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.interior_nonempty.mono interior_subset
#align topological_space.positive_compacts.nonempty TopologicalSpace.PositiveCompacts.nonempty
/-- Reinterpret a positive compact as a nonempty compact. -/
def toNonemptyCompacts (s : PositiveCompacts Ξ±) : NonemptyCompacts Ξ± :=
β¨s.toCompacts, s.nonemptyβ©
#align topological_space.positive_compacts.to_nonempty_compacts TopologicalSpace.PositiveCompacts.toNonemptyCompacts
@[ext]
protected theorem ext {s t : PositiveCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.positive_compacts.ext TopologicalSpace.PositiveCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.positive_compacts.coe_mk TopologicalSpace.PositiveCompacts.coe_mk
-- porting note: `@[simp]` moved to a new lemma
theorem carrier_eq_coe (s : PositiveCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.positive_compacts.carrier_eq_coe TopologicalSpace.PositiveCompacts.carrier_eq_coe
@[simp]
theorem coe_toCompacts (s : PositiveCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s :=
rfl
instance : Sup (PositiveCompacts Ξ±) :=
β¨fun s t =>
β¨s.toCompacts β t.toCompacts,
s.interior_nonempty.mono <| interior_mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (PositiveCompacts Ξ±) :=
β¨β¨β€, interior_univ.symm.subst univ_nonemptyβ©β©
instance : SemilatticeSup (PositiveCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (PositiveCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : PositiveCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : PositiveCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.positive_compacts.coe_top TopologicalSpace.PositiveCompacts.coe_top
/-- The image of a positive compact set under a continuous open map. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (hf' : IsOpenMap f) (K : PositiveCompacts Ξ±) :
PositiveCompacts Ξ² :=
{ Compacts.map f hf K.toCompacts with
interior_nonempty' :=
(K.interior_nonempty'.image _).mono (hf'.image_interior_subset K.toCompacts) }
#align topological_space.positive_compacts.map TopologicalSpace.PositiveCompacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (hf' : IsOpenMap f) (s : PositiveCompacts Ξ±) :
(s.map f hf hf' : Set Ξ²) = f '' s :=
rfl
#align topological_space.positive_compacts.coe_map TopologicalSpace.PositiveCompacts.coe_map
@[simp]
theorem map_id (K : PositiveCompacts Ξ±) : K.map id continuous_id IsOpenMap.id = K :=
PositiveCompacts.ext <| Set.image_id _
#align topological_space.positive_compacts.map_id TopologicalSpace.PositiveCompacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f)
(hg' : IsOpenMap g) (K : PositiveCompacts Ξ±) :
K.map (f β g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' :=
PositiveCompacts.ext <| Set.image_comp _ _ _
#align topological_space.positive_compacts.map_comp TopologicalSpace.PositiveCompacts.map_comp
theorem _root_.exists_positiveCompacts_subset [LocallyCompactSpace Ξ±] {U : Set Ξ±} (ho : IsOpen U)
(hn : U.Nonempty) : β K : PositiveCompacts Ξ±, βK β U :=
let β¨x, hxβ© := hn
let β¨K, hKc, hxK, hKUβ© := exists_compact_subset ho hx
β¨β¨β¨K, hKcβ©, β¨x, hxKβ©β©, hKUβ©
#align exists_positive_compacts_subset exists_positiveCompacts_subset
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Inhabited (PositiveCompacts Ξ±) :=
β¨β€β©
/-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/
instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by
inhabit Ξ±
rcases exists_compact_mem_nhds (default : Ξ±) with β¨K, hKc, hKβ©
| exact β¨β¨K, hKcβ©, _, mem_interior_iff_mem_nhds.2 hKβ© | /-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/
instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by
inhabit Ξ±
rcases exists_compact_mem_nhds (default : Ξ±) with β¨K, hKc, hKβ©
| Mathlib.Topology.Sets.Compacts.424_0.XVs1udLPbHOIEoW | /-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/
instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) | Mathlib_Topology_Sets_Compacts |
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
K : PositiveCompacts Ξ±
L : PositiveCompacts Ξ²
β’ Set.Nonempty (interior (Compacts.prod K.toCompacts L.toCompacts).carrier) | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
ext1
simp only [coe_map, β image_comp, f.self_comp_symm, image_id]
#align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv
@[simp]
theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ :=
Equiv.ext map_id
#align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl
@[simp]
theorem equiv_trans (f : Ξ± ββ Ξ²) (g : Ξ² ββ Ξ³) :
Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) :=
-- porting note: can no longer write `map_comp _ _ _ _` and unify
Equiv.ext <| map_comp g f g.continuous f.continuous
#align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans
@[simp]
theorem equiv_symm (f : Ξ± ββ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm :=
rfl
#align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm
/-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/
theorem coe_equiv_apply_eq_preimage (f : Ξ± ββ Ξ²) (K : Compacts Ξ±) :
(Compacts.equiv f K : Set Ξ²) = f.symm β»ΒΉ' (K : Set Ξ±) :=
f.toEquiv.image_eq_preimage K
#align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage
/-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product
space. -/
protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ Ξ²) where
carrier := K ΓΛ’ L
isCompact' := IsCompact.prod K.2 L.2
#align topological_space.compacts.prod TopologicalSpace.Compacts.prod
@[simp]
theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod
-- todo: add `pi`
end Compacts
/-! ### Nonempty compact sets -/
/-- The type of nonempty compact sets of a topological space. -/
structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
nonempty' : carrier.Nonempty
#align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts
namespace NonemptyCompacts
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections NonemptyCompacts (carrier β coe)
protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact
protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.nonempty'
#align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty
/-- Reinterpret a nonempty compact as a closed set. -/
def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± :=
β¨s, s.isCompact.isClosedβ©
#align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds
@[ext]
protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk
-- porting note: `@[simp]` moved to `coe_toCompacts`
theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe
@[simp] -- porting note: new lemma
theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl
instance : Sup (NonemptyCompacts Ξ±) :=
β¨fun s t => β¨s.toCompacts β t.toCompacts, s.nonempty.mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) :=
β¨β¨β€, univ_nonemptyβ©β©
instance : SemilatticeSup (NonemptyCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : NonemptyCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : NonemptyCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top
/-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with
default element the singleton set containing the default element. -/
instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) :=
β¨{ carrier := {default}
isCompact' := isCompact_singleton
nonempty' := singleton_nonempty _ }β©
instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s :=
isCompact_iff_compactSpace.1 s.isCompact
#align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace
instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s :=
s.nonempty.to_subtype
#align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty
/-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts`
in the product space. -/
protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ Ξ²) :=
{ K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty }
#align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod
@[simp]
theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod
end NonemptyCompacts
/-! ### Positive compact sets -/
/-- The type of compact sets with nonempty interior of a topological space.
See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/
structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
interior_nonempty' : (interior carrier).Nonempty
#align topological_space.positive_compacts TopologicalSpace.PositiveCompacts
namespace PositiveCompacts
instance : SetLike (PositiveCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : PositiveCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections PositiveCompacts (carrier β coe)
protected theorem isCompact (s : PositiveCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.positive_compacts.is_compact TopologicalSpace.PositiveCompacts.isCompact
theorem interior_nonempty (s : PositiveCompacts Ξ±) : (interior (s : Set Ξ±)).Nonempty :=
s.interior_nonempty'
#align topological_space.positive_compacts.interior_nonempty TopologicalSpace.PositiveCompacts.interior_nonempty
protected theorem nonempty (s : PositiveCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.interior_nonempty.mono interior_subset
#align topological_space.positive_compacts.nonempty TopologicalSpace.PositiveCompacts.nonempty
/-- Reinterpret a positive compact as a nonempty compact. -/
def toNonemptyCompacts (s : PositiveCompacts Ξ±) : NonemptyCompacts Ξ± :=
β¨s.toCompacts, s.nonemptyβ©
#align topological_space.positive_compacts.to_nonempty_compacts TopologicalSpace.PositiveCompacts.toNonemptyCompacts
@[ext]
protected theorem ext {s t : PositiveCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.positive_compacts.ext TopologicalSpace.PositiveCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.positive_compacts.coe_mk TopologicalSpace.PositiveCompacts.coe_mk
-- porting note: `@[simp]` moved to a new lemma
theorem carrier_eq_coe (s : PositiveCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.positive_compacts.carrier_eq_coe TopologicalSpace.PositiveCompacts.carrier_eq_coe
@[simp]
theorem coe_toCompacts (s : PositiveCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s :=
rfl
instance : Sup (PositiveCompacts Ξ±) :=
β¨fun s t =>
β¨s.toCompacts β t.toCompacts,
s.interior_nonempty.mono <| interior_mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (PositiveCompacts Ξ±) :=
β¨β¨β€, interior_univ.symm.subst univ_nonemptyβ©β©
instance : SemilatticeSup (PositiveCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (PositiveCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : PositiveCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : PositiveCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.positive_compacts.coe_top TopologicalSpace.PositiveCompacts.coe_top
/-- The image of a positive compact set under a continuous open map. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (hf' : IsOpenMap f) (K : PositiveCompacts Ξ±) :
PositiveCompacts Ξ² :=
{ Compacts.map f hf K.toCompacts with
interior_nonempty' :=
(K.interior_nonempty'.image _).mono (hf'.image_interior_subset K.toCompacts) }
#align topological_space.positive_compacts.map TopologicalSpace.PositiveCompacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (hf' : IsOpenMap f) (s : PositiveCompacts Ξ±) :
(s.map f hf hf' : Set Ξ²) = f '' s :=
rfl
#align topological_space.positive_compacts.coe_map TopologicalSpace.PositiveCompacts.coe_map
@[simp]
theorem map_id (K : PositiveCompacts Ξ±) : K.map id continuous_id IsOpenMap.id = K :=
PositiveCompacts.ext <| Set.image_id _
#align topological_space.positive_compacts.map_id TopologicalSpace.PositiveCompacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f)
(hg' : IsOpenMap g) (K : PositiveCompacts Ξ±) :
K.map (f β g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' :=
PositiveCompacts.ext <| Set.image_comp _ _ _
#align topological_space.positive_compacts.map_comp TopologicalSpace.PositiveCompacts.map_comp
theorem _root_.exists_positiveCompacts_subset [LocallyCompactSpace Ξ±] {U : Set Ξ±} (ho : IsOpen U)
(hn : U.Nonempty) : β K : PositiveCompacts Ξ±, βK β U :=
let β¨x, hxβ© := hn
let β¨K, hKc, hxK, hKUβ© := exists_compact_subset ho hx
β¨β¨β¨K, hKcβ©, β¨x, hxKβ©β©, hKUβ©
#align exists_positive_compacts_subset exists_positiveCompacts_subset
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Inhabited (PositiveCompacts Ξ±) :=
β¨β€β©
/-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/
instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by
inhabit Ξ±
rcases exists_compact_mem_nhds (default : Ξ±) with β¨K, hKc, hKβ©
exact β¨β¨K, hKcβ©, _, mem_interior_iff_mem_nhds.2 hKβ©
#align topological_space.positive_compacts.nonempty' TopologicalSpace.PositiveCompacts.nonempty'
/-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts`
in the product space. -/
protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) :
PositiveCompacts (Ξ± Γ Ξ²) where
toCompacts := K.toCompacts.prod L.toCompacts
interior_nonempty' := by
| simp only [Compacts.carrier_eq_coe, Compacts.coe_prod, interior_prod_eq] | /-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts`
in the product space. -/
protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) :
PositiveCompacts (Ξ± Γ Ξ²) where
toCompacts := K.toCompacts.prod L.toCompacts
interior_nonempty' := by
| Mathlib.Topology.Sets.Compacts.431_0.XVs1udLPbHOIEoW | /-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts`
in the product space. -/
protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) :
PositiveCompacts (Ξ± Γ Ξ²) where
toCompacts | Mathlib_Topology_Sets_Compacts |
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
K : PositiveCompacts Ξ±
L : PositiveCompacts Ξ²
β’ Set.Nonempty (interior βK.toCompacts ΓΛ’ interior βL.toCompacts) | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
ext1
simp only [coe_map, β image_comp, f.self_comp_symm, image_id]
#align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv
@[simp]
theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ :=
Equiv.ext map_id
#align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl
@[simp]
theorem equiv_trans (f : Ξ± ββ Ξ²) (g : Ξ² ββ Ξ³) :
Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) :=
-- porting note: can no longer write `map_comp _ _ _ _` and unify
Equiv.ext <| map_comp g f g.continuous f.continuous
#align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans
@[simp]
theorem equiv_symm (f : Ξ± ββ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm :=
rfl
#align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm
/-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/
theorem coe_equiv_apply_eq_preimage (f : Ξ± ββ Ξ²) (K : Compacts Ξ±) :
(Compacts.equiv f K : Set Ξ²) = f.symm β»ΒΉ' (K : Set Ξ±) :=
f.toEquiv.image_eq_preimage K
#align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage
/-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product
space. -/
protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ Ξ²) where
carrier := K ΓΛ’ L
isCompact' := IsCompact.prod K.2 L.2
#align topological_space.compacts.prod TopologicalSpace.Compacts.prod
@[simp]
theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod
-- todo: add `pi`
end Compacts
/-! ### Nonempty compact sets -/
/-- The type of nonempty compact sets of a topological space. -/
structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
nonempty' : carrier.Nonempty
#align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts
namespace NonemptyCompacts
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections NonemptyCompacts (carrier β coe)
protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact
protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.nonempty'
#align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty
/-- Reinterpret a nonempty compact as a closed set. -/
def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± :=
β¨s, s.isCompact.isClosedβ©
#align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds
@[ext]
protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk
-- porting note: `@[simp]` moved to `coe_toCompacts`
theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe
@[simp] -- porting note: new lemma
theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl
instance : Sup (NonemptyCompacts Ξ±) :=
β¨fun s t => β¨s.toCompacts β t.toCompacts, s.nonempty.mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) :=
β¨β¨β€, univ_nonemptyβ©β©
instance : SemilatticeSup (NonemptyCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : NonemptyCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : NonemptyCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top
/-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with
default element the singleton set containing the default element. -/
instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) :=
β¨{ carrier := {default}
isCompact' := isCompact_singleton
nonempty' := singleton_nonempty _ }β©
instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s :=
isCompact_iff_compactSpace.1 s.isCompact
#align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace
instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s :=
s.nonempty.to_subtype
#align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty
/-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts`
in the product space. -/
protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ Ξ²) :=
{ K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty }
#align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod
@[simp]
theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod
end NonemptyCompacts
/-! ### Positive compact sets -/
/-- The type of compact sets with nonempty interior of a topological space.
See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/
structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
interior_nonempty' : (interior carrier).Nonempty
#align topological_space.positive_compacts TopologicalSpace.PositiveCompacts
namespace PositiveCompacts
instance : SetLike (PositiveCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : PositiveCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections PositiveCompacts (carrier β coe)
protected theorem isCompact (s : PositiveCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.positive_compacts.is_compact TopologicalSpace.PositiveCompacts.isCompact
theorem interior_nonempty (s : PositiveCompacts Ξ±) : (interior (s : Set Ξ±)).Nonempty :=
s.interior_nonempty'
#align topological_space.positive_compacts.interior_nonempty TopologicalSpace.PositiveCompacts.interior_nonempty
protected theorem nonempty (s : PositiveCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.interior_nonempty.mono interior_subset
#align topological_space.positive_compacts.nonempty TopologicalSpace.PositiveCompacts.nonempty
/-- Reinterpret a positive compact as a nonempty compact. -/
def toNonemptyCompacts (s : PositiveCompacts Ξ±) : NonemptyCompacts Ξ± :=
β¨s.toCompacts, s.nonemptyβ©
#align topological_space.positive_compacts.to_nonempty_compacts TopologicalSpace.PositiveCompacts.toNonemptyCompacts
@[ext]
protected theorem ext {s t : PositiveCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.positive_compacts.ext TopologicalSpace.PositiveCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.positive_compacts.coe_mk TopologicalSpace.PositiveCompacts.coe_mk
-- porting note: `@[simp]` moved to a new lemma
theorem carrier_eq_coe (s : PositiveCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.positive_compacts.carrier_eq_coe TopologicalSpace.PositiveCompacts.carrier_eq_coe
@[simp]
theorem coe_toCompacts (s : PositiveCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s :=
rfl
instance : Sup (PositiveCompacts Ξ±) :=
β¨fun s t =>
β¨s.toCompacts β t.toCompacts,
s.interior_nonempty.mono <| interior_mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (PositiveCompacts Ξ±) :=
β¨β¨β€, interior_univ.symm.subst univ_nonemptyβ©β©
instance : SemilatticeSup (PositiveCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (PositiveCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : PositiveCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : PositiveCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.positive_compacts.coe_top TopologicalSpace.PositiveCompacts.coe_top
/-- The image of a positive compact set under a continuous open map. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (hf' : IsOpenMap f) (K : PositiveCompacts Ξ±) :
PositiveCompacts Ξ² :=
{ Compacts.map f hf K.toCompacts with
interior_nonempty' :=
(K.interior_nonempty'.image _).mono (hf'.image_interior_subset K.toCompacts) }
#align topological_space.positive_compacts.map TopologicalSpace.PositiveCompacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (hf' : IsOpenMap f) (s : PositiveCompacts Ξ±) :
(s.map f hf hf' : Set Ξ²) = f '' s :=
rfl
#align topological_space.positive_compacts.coe_map TopologicalSpace.PositiveCompacts.coe_map
@[simp]
theorem map_id (K : PositiveCompacts Ξ±) : K.map id continuous_id IsOpenMap.id = K :=
PositiveCompacts.ext <| Set.image_id _
#align topological_space.positive_compacts.map_id TopologicalSpace.PositiveCompacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f)
(hg' : IsOpenMap g) (K : PositiveCompacts Ξ±) :
K.map (f β g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' :=
PositiveCompacts.ext <| Set.image_comp _ _ _
#align topological_space.positive_compacts.map_comp TopologicalSpace.PositiveCompacts.map_comp
theorem _root_.exists_positiveCompacts_subset [LocallyCompactSpace Ξ±] {U : Set Ξ±} (ho : IsOpen U)
(hn : U.Nonempty) : β K : PositiveCompacts Ξ±, βK β U :=
let β¨x, hxβ© := hn
let β¨K, hKc, hxK, hKUβ© := exists_compact_subset ho hx
β¨β¨β¨K, hKcβ©, β¨x, hxKβ©β©, hKUβ©
#align exists_positive_compacts_subset exists_positiveCompacts_subset
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Inhabited (PositiveCompacts Ξ±) :=
β¨β€β©
/-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/
instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by
inhabit Ξ±
rcases exists_compact_mem_nhds (default : Ξ±) with β¨K, hKc, hKβ©
exact β¨β¨K, hKcβ©, _, mem_interior_iff_mem_nhds.2 hKβ©
#align topological_space.positive_compacts.nonempty' TopologicalSpace.PositiveCompacts.nonempty'
/-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts`
in the product space. -/
protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) :
PositiveCompacts (Ξ± Γ Ξ²) where
toCompacts := K.toCompacts.prod L.toCompacts
interior_nonempty' := by
simp only [Compacts.carrier_eq_coe, Compacts.coe_prod, interior_prod_eq]
| exact K.interior_nonempty.prod L.interior_nonempty | /-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts`
in the product space. -/
protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) :
PositiveCompacts (Ξ± Γ Ξ²) where
toCompacts := K.toCompacts.prod L.toCompacts
interior_nonempty' := by
simp only [Compacts.carrier_eq_coe, Compacts.coe_prod, interior_prod_eq]
| Mathlib.Topology.Sets.Compacts.431_0.XVs1udLPbHOIEoW | /-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts`
in the product space. -/
protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) :
PositiveCompacts (Ξ± Γ Ξ²) where
toCompacts | Mathlib_Topology_Sets_Compacts |
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
s t : CompactOpens Ξ±
h : (fun s => s.carrier) s = (fun s => s.carrier) t
β’ s = t | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
ext1
simp only [coe_map, β image_comp, f.self_comp_symm, image_id]
#align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv
@[simp]
theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ :=
Equiv.ext map_id
#align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl
@[simp]
theorem equiv_trans (f : Ξ± ββ Ξ²) (g : Ξ² ββ Ξ³) :
Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) :=
-- porting note: can no longer write `map_comp _ _ _ _` and unify
Equiv.ext <| map_comp g f g.continuous f.continuous
#align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans
@[simp]
theorem equiv_symm (f : Ξ± ββ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm :=
rfl
#align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm
/-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/
theorem coe_equiv_apply_eq_preimage (f : Ξ± ββ Ξ²) (K : Compacts Ξ±) :
(Compacts.equiv f K : Set Ξ²) = f.symm β»ΒΉ' (K : Set Ξ±) :=
f.toEquiv.image_eq_preimage K
#align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage
/-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product
space. -/
protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ Ξ²) where
carrier := K ΓΛ’ L
isCompact' := IsCompact.prod K.2 L.2
#align topological_space.compacts.prod TopologicalSpace.Compacts.prod
@[simp]
theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod
-- todo: add `pi`
end Compacts
/-! ### Nonempty compact sets -/
/-- The type of nonempty compact sets of a topological space. -/
structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
nonempty' : carrier.Nonempty
#align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts
namespace NonemptyCompacts
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections NonemptyCompacts (carrier β coe)
protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact
protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.nonempty'
#align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty
/-- Reinterpret a nonempty compact as a closed set. -/
def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± :=
β¨s, s.isCompact.isClosedβ©
#align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds
@[ext]
protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk
-- porting note: `@[simp]` moved to `coe_toCompacts`
theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe
@[simp] -- porting note: new lemma
theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl
instance : Sup (NonemptyCompacts Ξ±) :=
β¨fun s t => β¨s.toCompacts β t.toCompacts, s.nonempty.mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) :=
β¨β¨β€, univ_nonemptyβ©β©
instance : SemilatticeSup (NonemptyCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : NonemptyCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : NonemptyCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top
/-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with
default element the singleton set containing the default element. -/
instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) :=
β¨{ carrier := {default}
isCompact' := isCompact_singleton
nonempty' := singleton_nonempty _ }β©
instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s :=
isCompact_iff_compactSpace.1 s.isCompact
#align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace
instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s :=
s.nonempty.to_subtype
#align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty
/-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts`
in the product space. -/
protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ Ξ²) :=
{ K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty }
#align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod
@[simp]
theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod
end NonemptyCompacts
/-! ### Positive compact sets -/
/-- The type of compact sets with nonempty interior of a topological space.
See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/
structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
interior_nonempty' : (interior carrier).Nonempty
#align topological_space.positive_compacts TopologicalSpace.PositiveCompacts
namespace PositiveCompacts
instance : SetLike (PositiveCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : PositiveCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections PositiveCompacts (carrier β coe)
protected theorem isCompact (s : PositiveCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.positive_compacts.is_compact TopologicalSpace.PositiveCompacts.isCompact
theorem interior_nonempty (s : PositiveCompacts Ξ±) : (interior (s : Set Ξ±)).Nonempty :=
s.interior_nonempty'
#align topological_space.positive_compacts.interior_nonempty TopologicalSpace.PositiveCompacts.interior_nonempty
protected theorem nonempty (s : PositiveCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.interior_nonempty.mono interior_subset
#align topological_space.positive_compacts.nonempty TopologicalSpace.PositiveCompacts.nonempty
/-- Reinterpret a positive compact as a nonempty compact. -/
def toNonemptyCompacts (s : PositiveCompacts Ξ±) : NonemptyCompacts Ξ± :=
β¨s.toCompacts, s.nonemptyβ©
#align topological_space.positive_compacts.to_nonempty_compacts TopologicalSpace.PositiveCompacts.toNonemptyCompacts
@[ext]
protected theorem ext {s t : PositiveCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.positive_compacts.ext TopologicalSpace.PositiveCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.positive_compacts.coe_mk TopologicalSpace.PositiveCompacts.coe_mk
-- porting note: `@[simp]` moved to a new lemma
theorem carrier_eq_coe (s : PositiveCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.positive_compacts.carrier_eq_coe TopologicalSpace.PositiveCompacts.carrier_eq_coe
@[simp]
theorem coe_toCompacts (s : PositiveCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s :=
rfl
instance : Sup (PositiveCompacts Ξ±) :=
β¨fun s t =>
β¨s.toCompacts β t.toCompacts,
s.interior_nonempty.mono <| interior_mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (PositiveCompacts Ξ±) :=
β¨β¨β€, interior_univ.symm.subst univ_nonemptyβ©β©
instance : SemilatticeSup (PositiveCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (PositiveCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : PositiveCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : PositiveCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.positive_compacts.coe_top TopologicalSpace.PositiveCompacts.coe_top
/-- The image of a positive compact set under a continuous open map. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (hf' : IsOpenMap f) (K : PositiveCompacts Ξ±) :
PositiveCompacts Ξ² :=
{ Compacts.map f hf K.toCompacts with
interior_nonempty' :=
(K.interior_nonempty'.image _).mono (hf'.image_interior_subset K.toCompacts) }
#align topological_space.positive_compacts.map TopologicalSpace.PositiveCompacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (hf' : IsOpenMap f) (s : PositiveCompacts Ξ±) :
(s.map f hf hf' : Set Ξ²) = f '' s :=
rfl
#align topological_space.positive_compacts.coe_map TopologicalSpace.PositiveCompacts.coe_map
@[simp]
theorem map_id (K : PositiveCompacts Ξ±) : K.map id continuous_id IsOpenMap.id = K :=
PositiveCompacts.ext <| Set.image_id _
#align topological_space.positive_compacts.map_id TopologicalSpace.PositiveCompacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f)
(hg' : IsOpenMap g) (K : PositiveCompacts Ξ±) :
K.map (f β g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' :=
PositiveCompacts.ext <| Set.image_comp _ _ _
#align topological_space.positive_compacts.map_comp TopologicalSpace.PositiveCompacts.map_comp
theorem _root_.exists_positiveCompacts_subset [LocallyCompactSpace Ξ±] {U : Set Ξ±} (ho : IsOpen U)
(hn : U.Nonempty) : β K : PositiveCompacts Ξ±, βK β U :=
let β¨x, hxβ© := hn
let β¨K, hKc, hxK, hKUβ© := exists_compact_subset ho hx
β¨β¨β¨K, hKcβ©, β¨x, hxKβ©β©, hKUβ©
#align exists_positive_compacts_subset exists_positiveCompacts_subset
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Inhabited (PositiveCompacts Ξ±) :=
β¨β€β©
/-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/
instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by
inhabit Ξ±
rcases exists_compact_mem_nhds (default : Ξ±) with β¨K, hKc, hKβ©
exact β¨β¨K, hKcβ©, _, mem_interior_iff_mem_nhds.2 hKβ©
#align topological_space.positive_compacts.nonempty' TopologicalSpace.PositiveCompacts.nonempty'
/-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts`
in the product space. -/
protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) :
PositiveCompacts (Ξ± Γ Ξ²) where
toCompacts := K.toCompacts.prod L.toCompacts
interior_nonempty' := by
simp only [Compacts.carrier_eq_coe, Compacts.coe_prod, interior_prod_eq]
exact K.interior_nonempty.prod L.interior_nonempty
#align topological_space.positive_compacts.prod TopologicalSpace.PositiveCompacts.prod
@[simp]
theorem coe_prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.positive_compacts.coe_prod TopologicalSpace.PositiveCompacts.coe_prod
end PositiveCompacts
/-! ### Compact open sets -/
/-- The type of compact open sets of a topological space. This is useful in non Hausdorff contexts,
in particular spectral spaces. -/
structure CompactOpens (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
isOpen' : IsOpen carrier
#align topological_space.compact_opens TopologicalSpace.CompactOpens
namespace CompactOpens
instance : SetLike (CompactOpens Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
| obtain β¨β¨_, _β©, _β© := s | instance : SetLike (CompactOpens Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
| Mathlib.Topology.Sets.Compacts.459_0.XVs1udLPbHOIEoW | instance : SetLike (CompactOpens Ξ±) Ξ± where
coe s | Mathlib_Topology_Sets_Compacts |
case mk.mk
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
t : CompactOpens Ξ±
carrierβ : Set Ξ±
isCompact'β : IsCompact carrierβ
isOpen'β : IsOpen { carrier := carrierβ, isCompact' := isCompact'β }.carrier
h :
(fun s => s.carrier) { toCompacts := { carrier := carrierβ, isCompact' := isCompact'β }, isOpen' := isOpen'β } =
(fun s => s.carrier) t
β’ { toCompacts := { carrier := carrierβ, isCompact' := isCompact'β }, isOpen' := isOpen'β } = t | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
ext1
simp only [coe_map, β image_comp, f.self_comp_symm, image_id]
#align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv
@[simp]
theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ :=
Equiv.ext map_id
#align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl
@[simp]
theorem equiv_trans (f : Ξ± ββ Ξ²) (g : Ξ² ββ Ξ³) :
Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) :=
-- porting note: can no longer write `map_comp _ _ _ _` and unify
Equiv.ext <| map_comp g f g.continuous f.continuous
#align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans
@[simp]
theorem equiv_symm (f : Ξ± ββ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm :=
rfl
#align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm
/-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/
theorem coe_equiv_apply_eq_preimage (f : Ξ± ββ Ξ²) (K : Compacts Ξ±) :
(Compacts.equiv f K : Set Ξ²) = f.symm β»ΒΉ' (K : Set Ξ±) :=
f.toEquiv.image_eq_preimage K
#align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage
/-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product
space. -/
protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ Ξ²) where
carrier := K ΓΛ’ L
isCompact' := IsCompact.prod K.2 L.2
#align topological_space.compacts.prod TopologicalSpace.Compacts.prod
@[simp]
theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod
-- todo: add `pi`
end Compacts
/-! ### Nonempty compact sets -/
/-- The type of nonempty compact sets of a topological space. -/
structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
nonempty' : carrier.Nonempty
#align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts
namespace NonemptyCompacts
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections NonemptyCompacts (carrier β coe)
protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact
protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.nonempty'
#align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty
/-- Reinterpret a nonempty compact as a closed set. -/
def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± :=
β¨s, s.isCompact.isClosedβ©
#align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds
@[ext]
protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk
-- porting note: `@[simp]` moved to `coe_toCompacts`
theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe
@[simp] -- porting note: new lemma
theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl
instance : Sup (NonemptyCompacts Ξ±) :=
β¨fun s t => β¨s.toCompacts β t.toCompacts, s.nonempty.mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) :=
β¨β¨β€, univ_nonemptyβ©β©
instance : SemilatticeSup (NonemptyCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : NonemptyCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : NonemptyCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top
/-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with
default element the singleton set containing the default element. -/
instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) :=
β¨{ carrier := {default}
isCompact' := isCompact_singleton
nonempty' := singleton_nonempty _ }β©
instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s :=
isCompact_iff_compactSpace.1 s.isCompact
#align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace
instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s :=
s.nonempty.to_subtype
#align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty
/-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts`
in the product space. -/
protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ Ξ²) :=
{ K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty }
#align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod
@[simp]
theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod
end NonemptyCompacts
/-! ### Positive compact sets -/
/-- The type of compact sets with nonempty interior of a topological space.
See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/
structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
interior_nonempty' : (interior carrier).Nonempty
#align topological_space.positive_compacts TopologicalSpace.PositiveCompacts
namespace PositiveCompacts
instance : SetLike (PositiveCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : PositiveCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections PositiveCompacts (carrier β coe)
protected theorem isCompact (s : PositiveCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.positive_compacts.is_compact TopologicalSpace.PositiveCompacts.isCompact
theorem interior_nonempty (s : PositiveCompacts Ξ±) : (interior (s : Set Ξ±)).Nonempty :=
s.interior_nonempty'
#align topological_space.positive_compacts.interior_nonempty TopologicalSpace.PositiveCompacts.interior_nonempty
protected theorem nonempty (s : PositiveCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.interior_nonempty.mono interior_subset
#align topological_space.positive_compacts.nonempty TopologicalSpace.PositiveCompacts.nonempty
/-- Reinterpret a positive compact as a nonempty compact. -/
def toNonemptyCompacts (s : PositiveCompacts Ξ±) : NonemptyCompacts Ξ± :=
β¨s.toCompacts, s.nonemptyβ©
#align topological_space.positive_compacts.to_nonempty_compacts TopologicalSpace.PositiveCompacts.toNonemptyCompacts
@[ext]
protected theorem ext {s t : PositiveCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.positive_compacts.ext TopologicalSpace.PositiveCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.positive_compacts.coe_mk TopologicalSpace.PositiveCompacts.coe_mk
-- porting note: `@[simp]` moved to a new lemma
theorem carrier_eq_coe (s : PositiveCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.positive_compacts.carrier_eq_coe TopologicalSpace.PositiveCompacts.carrier_eq_coe
@[simp]
theorem coe_toCompacts (s : PositiveCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s :=
rfl
instance : Sup (PositiveCompacts Ξ±) :=
β¨fun s t =>
β¨s.toCompacts β t.toCompacts,
s.interior_nonempty.mono <| interior_mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (PositiveCompacts Ξ±) :=
β¨β¨β€, interior_univ.symm.subst univ_nonemptyβ©β©
instance : SemilatticeSup (PositiveCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (PositiveCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : PositiveCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : PositiveCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.positive_compacts.coe_top TopologicalSpace.PositiveCompacts.coe_top
/-- The image of a positive compact set under a continuous open map. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (hf' : IsOpenMap f) (K : PositiveCompacts Ξ±) :
PositiveCompacts Ξ² :=
{ Compacts.map f hf K.toCompacts with
interior_nonempty' :=
(K.interior_nonempty'.image _).mono (hf'.image_interior_subset K.toCompacts) }
#align topological_space.positive_compacts.map TopologicalSpace.PositiveCompacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (hf' : IsOpenMap f) (s : PositiveCompacts Ξ±) :
(s.map f hf hf' : Set Ξ²) = f '' s :=
rfl
#align topological_space.positive_compacts.coe_map TopologicalSpace.PositiveCompacts.coe_map
@[simp]
theorem map_id (K : PositiveCompacts Ξ±) : K.map id continuous_id IsOpenMap.id = K :=
PositiveCompacts.ext <| Set.image_id _
#align topological_space.positive_compacts.map_id TopologicalSpace.PositiveCompacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f)
(hg' : IsOpenMap g) (K : PositiveCompacts Ξ±) :
K.map (f β g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' :=
PositiveCompacts.ext <| Set.image_comp _ _ _
#align topological_space.positive_compacts.map_comp TopologicalSpace.PositiveCompacts.map_comp
theorem _root_.exists_positiveCompacts_subset [LocallyCompactSpace Ξ±] {U : Set Ξ±} (ho : IsOpen U)
(hn : U.Nonempty) : β K : PositiveCompacts Ξ±, βK β U :=
let β¨x, hxβ© := hn
let β¨K, hKc, hxK, hKUβ© := exists_compact_subset ho hx
β¨β¨β¨K, hKcβ©, β¨x, hxKβ©β©, hKUβ©
#align exists_positive_compacts_subset exists_positiveCompacts_subset
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Inhabited (PositiveCompacts Ξ±) :=
β¨β€β©
/-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/
instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by
inhabit Ξ±
rcases exists_compact_mem_nhds (default : Ξ±) with β¨K, hKc, hKβ©
exact β¨β¨K, hKcβ©, _, mem_interior_iff_mem_nhds.2 hKβ©
#align topological_space.positive_compacts.nonempty' TopologicalSpace.PositiveCompacts.nonempty'
/-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts`
in the product space. -/
protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) :
PositiveCompacts (Ξ± Γ Ξ²) where
toCompacts := K.toCompacts.prod L.toCompacts
interior_nonempty' := by
simp only [Compacts.carrier_eq_coe, Compacts.coe_prod, interior_prod_eq]
exact K.interior_nonempty.prod L.interior_nonempty
#align topological_space.positive_compacts.prod TopologicalSpace.PositiveCompacts.prod
@[simp]
theorem coe_prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.positive_compacts.coe_prod TopologicalSpace.PositiveCompacts.coe_prod
end PositiveCompacts
/-! ### Compact open sets -/
/-- The type of compact open sets of a topological space. This is useful in non Hausdorff contexts,
in particular spectral spaces. -/
structure CompactOpens (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
isOpen' : IsOpen carrier
#align topological_space.compact_opens TopologicalSpace.CompactOpens
namespace CompactOpens
instance : SetLike (CompactOpens Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
| obtain β¨β¨_, _β©, _β© := t | instance : SetLike (CompactOpens Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
| Mathlib.Topology.Sets.Compacts.459_0.XVs1udLPbHOIEoW | instance : SetLike (CompactOpens Ξ±) Ξ± where
coe s | Mathlib_Topology_Sets_Compacts |
case mk.mk.mk.mk
Ξ± : Type u_1
Ξ² : Type u_2
Ξ³ : Type u_3
instβΒ² : TopologicalSpace Ξ±
instβΒΉ : TopologicalSpace Ξ²
instβ : TopologicalSpace Ξ³
carrierβΒΉ : Set Ξ±
isCompact'βΒΉ : IsCompact carrierβΒΉ
isOpen'βΒΉ : IsOpen { carrier := carrierβΒΉ, isCompact' := isCompact'βΒΉ }.carrier
carrierβ : Set Ξ±
isCompact'β : IsCompact carrierβ
isOpen'β : IsOpen { carrier := carrierβ, isCompact' := isCompact'β }.carrier
h :
(fun s => s.carrier) { toCompacts := { carrier := carrierβΒΉ, isCompact' := isCompact'βΒΉ }, isOpen' := isOpen'βΒΉ } =
(fun s => s.carrier) { toCompacts := { carrier := carrierβ, isCompact' := isCompact'β }, isOpen' := isOpen'β }
β’ { toCompacts := { carrier := carrierβΒΉ, isCompact' := isCompact'βΒΉ }, isOpen' := isOpen'βΒΉ } =
{ toCompacts := { carrier := carrierβ, isCompact' := isCompact'β }, isOpen' := isOpen'β } | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.QuasiSeparated
#align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47"
/-!
# Compact sets
We define a few types of compact sets in a topological space.
## Main Definitions
For a topological space `Ξ±`,
* `TopologicalSpace.Compacts Ξ±`: The type of compact sets.
* `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets.
* `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior.
* `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the
study of spectral spaces.
-/
open Set
variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³]
namespace TopologicalSpace
/-! ### Compact sets -/
/-- The type of compact sets of a topological space. -/
structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where
carrier : Set Ξ±
isCompact' : IsCompact carrier
#align topological_space.compacts TopologicalSpace.Compacts
namespace Compacts
instance : SetLike (Compacts Ξ±) Ξ± where
coe := Compacts.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s
initialize_simps_projections Compacts (carrier β coe)
protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact
instance (K : Compacts Ξ±) : CompactSpace K :=
isCompact_iff_compactSpace.1 K.isCompact
instance : CanLift (Set Ξ±) (Compacts Ξ±) (β) IsCompact where prf K hK := β¨β¨K, hKβ©, rflβ©
@[ext]
protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.compacts.ext TopologicalSpace.Compacts.ext
@[simp]
theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk
@[simp]
theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe
instance : Sup (Compacts Ξ±) :=
β¨fun s t => β¨s βͺ t, s.isCompact.union t.isCompactβ©β©
instance [T2Space Ξ±] : Inf (Compacts Ξ±) :=
β¨fun s t => β¨s β© t, s.isCompact.inter t.isCompactβ©β©
instance [CompactSpace Ξ±] : Top (Compacts Ξ±) :=
β¨β¨univ, isCompact_univβ©β©
instance : Bot (Compacts Ξ±) :=
β¨β¨β
, isCompact_emptyβ©β©
instance : SemilatticeSup (Compacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) :=
SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
instance : OrderBot (Compacts Ξ±) :=
OrderBot.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) :=
BoundedOrder.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl rfl
/-- The type of compact sets is inhabited, with default element the empty set. -/
instance : Inhabited (Compacts Ξ±) := β¨β₯β©
@[simp]
theorem coe_sup (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup
@[simp]
theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (β(s β t) : Set Ξ±) = βs β© βt :=
rfl
#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf
@[simp]
theorem coe_top [CompactSpace Ξ±] : (β(β€ : Compacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top
@[simp]
theorem coe_bot : (β(β₯ : Compacts Ξ±) : Set Ξ±) = β
:=
rfl
#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot
@[simp]
theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β Compacts Ξ±} :
(β(s.sup f) : Set Ξ±) = s.sup fun i => β(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup
/-- The image of a compact set under a continuous function. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² :=
β¨f '' K.1, K.2.image hfβ©
#align topological_space.compacts.map TopologicalSpace.Compacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s :=
rfl
#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map
@[simp]
theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K :=
Compacts.ext <| Set.image_id _
#align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) :
K.map (f β g) (hf.comp hg) = (K.map g hg).map f hf :=
Compacts.ext <| Set.image_comp _ _ _
#align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/
@[simps]
protected def equiv (f : Ξ± ββ Ξ²) : Compacts Ξ± β Compacts Ξ² where
toFun := Compacts.map f f.continuous
invFun := Compacts.map _ f.symm.continuous
left_inv s := by
ext1
simp only [coe_map, β image_comp, f.symm_comp_self, image_id]
right_inv s := by
ext1
simp only [coe_map, β image_comp, f.self_comp_symm, image_id]
#align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv
@[simp]
theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ :=
Equiv.ext map_id
#align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl
@[simp]
theorem equiv_trans (f : Ξ± ββ Ξ²) (g : Ξ² ββ Ξ³) :
Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) :=
-- porting note: can no longer write `map_comp _ _ _ _` and unify
Equiv.ext <| map_comp g f g.continuous f.continuous
#align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans
@[simp]
theorem equiv_symm (f : Ξ± ββ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm :=
rfl
#align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm
/-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/
theorem coe_equiv_apply_eq_preimage (f : Ξ± ββ Ξ²) (K : Compacts Ξ±) :
(Compacts.equiv f K : Set Ξ²) = f.symm β»ΒΉ' (K : Set Ξ±) :=
f.toEquiv.image_eq_preimage K
#align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage
/-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product
space. -/
protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ Ξ²) where
carrier := K ΓΛ’ L
isCompact' := IsCompact.prod K.2 L.2
#align topological_space.compacts.prod TopologicalSpace.Compacts.prod
@[simp]
theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod
-- todo: add `pi`
end Compacts
/-! ### Nonempty compact sets -/
/-- The type of nonempty compact sets of a topological space. -/
structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
nonempty' : carrier.Nonempty
#align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts
namespace NonemptyCompacts
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections NonemptyCompacts (carrier β coe)
protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact
protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.nonempty'
#align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty
/-- Reinterpret a nonempty compact as a closed set. -/
def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± :=
β¨s, s.isCompact.isClosedβ©
#align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds
@[ext]
protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk
-- porting note: `@[simp]` moved to `coe_toCompacts`
theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe
@[simp] -- porting note: new lemma
theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl
instance : Sup (NonemptyCompacts Ξ±) :=
β¨fun s t => β¨s.toCompacts β t.toCompacts, s.nonempty.mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) :=
β¨β¨β€, univ_nonemptyβ©β©
instance : SemilatticeSup (NonemptyCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : NonemptyCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : NonemptyCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top
/-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with
default element the singleton set containing the default element. -/
instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) :=
β¨{ carrier := {default}
isCompact' := isCompact_singleton
nonempty' := singleton_nonempty _ }β©
instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s :=
isCompact_iff_compactSpace.1 s.isCompact
#align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace
instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s :=
s.nonempty.to_subtype
#align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty
/-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts`
in the product space. -/
protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ Ξ²) :=
{ K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty }
#align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod
@[simp]
theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod
end NonemptyCompacts
/-! ### Positive compact sets -/
/-- The type of compact sets with nonempty interior of a topological space.
See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/
structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
interior_nonempty' : (interior carrier).Nonempty
#align topological_space.positive_compacts TopologicalSpace.PositiveCompacts
namespace PositiveCompacts
instance : SetLike (PositiveCompacts Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : PositiveCompacts Ξ±) : Set Ξ± := s
initialize_simps_projections PositiveCompacts (carrier β coe)
protected theorem isCompact (s : PositiveCompacts Ξ±) : IsCompact (s : Set Ξ±) :=
s.isCompact'
#align topological_space.positive_compacts.is_compact TopologicalSpace.PositiveCompacts.isCompact
theorem interior_nonempty (s : PositiveCompacts Ξ±) : (interior (s : Set Ξ±)).Nonempty :=
s.interior_nonempty'
#align topological_space.positive_compacts.interior_nonempty TopologicalSpace.PositiveCompacts.interior_nonempty
protected theorem nonempty (s : PositiveCompacts Ξ±) : (s : Set Ξ±).Nonempty :=
s.interior_nonempty.mono interior_subset
#align topological_space.positive_compacts.nonempty TopologicalSpace.PositiveCompacts.nonempty
/-- Reinterpret a positive compact as a nonempty compact. -/
def toNonemptyCompacts (s : PositiveCompacts Ξ±) : NonemptyCompacts Ξ± :=
β¨s.toCompacts, s.nonemptyβ©
#align topological_space.positive_compacts.to_nonempty_compacts TopologicalSpace.PositiveCompacts.toNonemptyCompacts
@[ext]
protected theorem ext {s t : PositiveCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t :=
SetLike.ext' h
#align topological_space.positive_compacts.ext TopologicalSpace.PositiveCompacts.ext
@[simp]
theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s :=
rfl
#align topological_space.positive_compacts.coe_mk TopologicalSpace.PositiveCompacts.coe_mk
-- porting note: `@[simp]` moved to a new lemma
theorem carrier_eq_coe (s : PositiveCompacts Ξ±) : s.carrier = s :=
rfl
#align topological_space.positive_compacts.carrier_eq_coe TopologicalSpace.PositiveCompacts.carrier_eq_coe
@[simp]
theorem coe_toCompacts (s : PositiveCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s :=
rfl
instance : Sup (PositiveCompacts Ξ±) :=
β¨fun s t =>
β¨s.toCompacts β t.toCompacts,
s.interior_nonempty.mono <| interior_mono <| subset_union_left _ _β©β©
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (PositiveCompacts Ξ±) :=
β¨β¨β€, interior_univ.symm.subst univ_nonemptyβ©β©
instance : SemilatticeSup (PositiveCompacts Ξ±) :=
SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl
instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (PositiveCompacts Ξ±) :=
OrderTop.lift ((β) : _ β Set Ξ±) (fun _ _ => id) rfl
@[simp]
theorem coe_sup (s t : PositiveCompacts Ξ±) : (β(s β t) : Set Ξ±) = βs βͺ βt :=
rfl
#align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup
@[simp]
theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (β(β€ : PositiveCompacts Ξ±) : Set Ξ±) = univ :=
rfl
#align topological_space.positive_compacts.coe_top TopologicalSpace.PositiveCompacts.coe_top
/-- The image of a positive compact set under a continuous open map. -/
protected def map (f : Ξ± β Ξ²) (hf : Continuous f) (hf' : IsOpenMap f) (K : PositiveCompacts Ξ±) :
PositiveCompacts Ξ² :=
{ Compacts.map f hf K.toCompacts with
interior_nonempty' :=
(K.interior_nonempty'.image _).mono (hf'.image_interior_subset K.toCompacts) }
#align topological_space.positive_compacts.map TopologicalSpace.PositiveCompacts.map
@[simp, norm_cast]
theorem coe_map {f : Ξ± β Ξ²} (hf : Continuous f) (hf' : IsOpenMap f) (s : PositiveCompacts Ξ±) :
(s.map f hf hf' : Set Ξ²) = f '' s :=
rfl
#align topological_space.positive_compacts.coe_map TopologicalSpace.PositiveCompacts.coe_map
@[simp]
theorem map_id (K : PositiveCompacts Ξ±) : K.map id continuous_id IsOpenMap.id = K :=
PositiveCompacts.ext <| Set.image_id _
#align topological_space.positive_compacts.map_id TopologicalSpace.PositiveCompacts.map_id
theorem map_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f)
(hg' : IsOpenMap g) (K : PositiveCompacts Ξ±) :
K.map (f β g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' :=
PositiveCompacts.ext <| Set.image_comp _ _ _
#align topological_space.positive_compacts.map_comp TopologicalSpace.PositiveCompacts.map_comp
theorem _root_.exists_positiveCompacts_subset [LocallyCompactSpace Ξ±] {U : Set Ξ±} (ho : IsOpen U)
(hn : U.Nonempty) : β K : PositiveCompacts Ξ±, βK β U :=
let β¨x, hxβ© := hn
let β¨K, hKc, hxK, hKUβ© := exists_compact_subset ho hx
β¨β¨β¨K, hKcβ©, β¨x, hxKβ©β©, hKUβ©
#align exists_positive_compacts_subset exists_positiveCompacts_subset
instance [CompactSpace Ξ±] [Nonempty Ξ±] : Inhabited (PositiveCompacts Ξ±) :=
β¨β€β©
/-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/
instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by
inhabit Ξ±
rcases exists_compact_mem_nhds (default : Ξ±) with β¨K, hKc, hKβ©
exact β¨β¨K, hKcβ©, _, mem_interior_iff_mem_nhds.2 hKβ©
#align topological_space.positive_compacts.nonempty' TopologicalSpace.PositiveCompacts.nonempty'
/-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts`
in the product space. -/
protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) :
PositiveCompacts (Ξ± Γ Ξ²) where
toCompacts := K.toCompacts.prod L.toCompacts
interior_nonempty' := by
simp only [Compacts.carrier_eq_coe, Compacts.coe_prod, interior_prod_eq]
exact K.interior_nonempty.prod L.interior_nonempty
#align topological_space.positive_compacts.prod TopologicalSpace.PositiveCompacts.prod
@[simp]
theorem coe_prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) :
(K.prod L : Set (Ξ± Γ Ξ²)) = (K : Set Ξ±) ΓΛ’ (L : Set Ξ²) :=
rfl
#align topological_space.positive_compacts.coe_prod TopologicalSpace.PositiveCompacts.coe_prod
end PositiveCompacts
/-! ### Compact open sets -/
/-- The type of compact open sets of a topological space. This is useful in non Hausdorff contexts,
in particular spectral spaces. -/
structure CompactOpens (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where
isOpen' : IsOpen carrier
#align topological_space.compact_opens TopologicalSpace.CompactOpens
namespace CompactOpens
instance : SetLike (CompactOpens Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
| congr | instance : SetLike (CompactOpens Ξ±) Ξ± where
coe s := s.carrier
coe_injective' s t h := by
obtain β¨β¨_, _β©, _β© := s
obtain β¨β¨_, _β©, _β© := t
| Mathlib.Topology.Sets.Compacts.459_0.XVs1udLPbHOIEoW | instance : SetLike (CompactOpens Ξ±) Ξ± where
coe s | Mathlib_Topology_Sets_Compacts |
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΅ : β
Ξ΅0 : Ξ΅ > 0
aβ bβ : β
h : dist aβ bβ < Ξ΅
β’ dist (-aβ) (-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, Mario Carneiro
-/
import Mathlib.Topology.Algebra.UniformMulAction
import Mathlib.Topology.Algebra.Star
import Mathlib.Topology.Algebra.Order.Field
import Mathlib.Algebra.Periodic
import Mathlib.Topology.Instances.Int
#align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd"
/-!
# Topological properties of β
-/
noncomputable section
open Classical Filter Int Metric Set TopologicalSpace Bornology
open scoped Topology Uniformity Interval
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
instance : NoncompactSpace β := Int.closedEmbedding_coe_real.noncompactSpace
theorem Real.uniformContinuous_add : UniformContinuous fun p : β Γ β => p.1 + p.2 :=
Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 =>
let β¨Ξ΄, Ξ΄0, HΞ΄β© := rat_add_continuous_lemma abs Ξ΅0
β¨Ξ΄, Ξ΄0, fun h =>
let β¨hβ, hββ© := max_lt_iff.1 h
HΞ΄ hβ hββ©
#align real.uniform_continuous_add Real.uniformContinuous_add
theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg β _) :=
Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 =>
β¨_, Ξ΅0, fun h => by | rw [dist_comm] at h | theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg β _) :=
Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 =>
β¨_, Ξ΅0, fun h => by | Mathlib.Topology.Instances.Real.38_0.cAejORboOY2cNtK | theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg β _) | Mathlib_Topology_Instances_Real |
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΅ : β
Ξ΅0 : Ξ΅ > 0
aβ bβ : β
h : dist bβ aβ < Ξ΅
β’ dist (-aβ) (-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, Mario Carneiro
-/
import Mathlib.Topology.Algebra.UniformMulAction
import Mathlib.Topology.Algebra.Star
import Mathlib.Topology.Algebra.Order.Field
import Mathlib.Algebra.Periodic
import Mathlib.Topology.Instances.Int
#align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd"
/-!
# Topological properties of β
-/
noncomputable section
open Classical Filter Int Metric Set TopologicalSpace Bornology
open scoped Topology Uniformity Interval
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
instance : NoncompactSpace β := Int.closedEmbedding_coe_real.noncompactSpace
theorem Real.uniformContinuous_add : UniformContinuous fun p : β Γ β => p.1 + p.2 :=
Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 =>
let β¨Ξ΄, Ξ΄0, HΞ΄β© := rat_add_continuous_lemma abs Ξ΅0
β¨Ξ΄, Ξ΄0, fun h =>
let β¨hβ, hββ© := max_lt_iff.1 h
HΞ΄ hβ hββ©
#align real.uniform_continuous_add Real.uniformContinuous_add
theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg β _) :=
Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 =>
β¨_, Ξ΅0, fun h => by rw [dist_comm] at h; | simpa only [Real.dist_eq, neg_sub_neg] using h | theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg β _) :=
Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 =>
β¨_, Ξ΅0, fun h => by rw [dist_comm] at h; | Mathlib.Topology.Instances.Real.38_0.cAejORboOY2cNtK | theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg β _) | Mathlib_Topology_Instances_Real |
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
β’ TopologicalAddGroup β | /-
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, Mario Carneiro
-/
import Mathlib.Topology.Algebra.UniformMulAction
import Mathlib.Topology.Algebra.Star
import Mathlib.Topology.Algebra.Order.Field
import Mathlib.Algebra.Periodic
import Mathlib.Topology.Instances.Int
#align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd"
/-!
# Topological properties of β
-/
noncomputable section
open Classical Filter Int Metric Set TopologicalSpace Bornology
open scoped Topology Uniformity Interval
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
instance : NoncompactSpace β := Int.closedEmbedding_coe_real.noncompactSpace
theorem Real.uniformContinuous_add : UniformContinuous fun p : β Γ β => p.1 + p.2 :=
Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 =>
let β¨Ξ΄, Ξ΄0, HΞ΄β© := rat_add_continuous_lemma abs Ξ΅0
β¨Ξ΄, Ξ΄0, fun h =>
let β¨hβ, hββ© := max_lt_iff.1 h
HΞ΄ hβ hββ©
#align real.uniform_continuous_add Real.uniformContinuous_add
theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg β _) :=
Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 =>
β¨_, Ξ΅0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using hβ©
#align real.uniform_continuous_neg Real.uniformContinuous_neg
instance : ContinuousStar β := β¨continuous_idβ©
instance : UniformAddGroup β :=
UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg
-- short-circuit type class inference
instance : TopologicalAddGroup β := by | infer_instance | instance : TopologicalAddGroup β := by | Mathlib.Topology.Instances.Real.49_0.cAejORboOY2cNtK | instance : TopologicalAddGroup β | Mathlib_Topology_Instances_Real |
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
x r : β
β’ IsCompact (closedBall x r) | /-
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, Mario Carneiro
-/
import Mathlib.Topology.Algebra.UniformMulAction
import Mathlib.Topology.Algebra.Star
import Mathlib.Topology.Algebra.Order.Field
import Mathlib.Algebra.Periodic
import Mathlib.Topology.Instances.Int
#align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd"
/-!
# Topological properties of β
-/
noncomputable section
open Classical Filter Int Metric Set TopologicalSpace Bornology
open scoped Topology Uniformity Interval
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
instance : NoncompactSpace β := Int.closedEmbedding_coe_real.noncompactSpace
theorem Real.uniformContinuous_add : UniformContinuous fun p : β Γ β => p.1 + p.2 :=
Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 =>
let β¨Ξ΄, Ξ΄0, HΞ΄β© := rat_add_continuous_lemma abs Ξ΅0
β¨Ξ΄, Ξ΄0, fun h =>
let β¨hβ, hββ© := max_lt_iff.1 h
HΞ΄ hβ hββ©
#align real.uniform_continuous_add Real.uniformContinuous_add
theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg β _) :=
Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 =>
β¨_, Ξ΅0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using hβ©
#align real.uniform_continuous_neg Real.uniformContinuous_neg
instance : ContinuousStar β := β¨continuous_idβ©
instance : UniformAddGroup β :=
UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg
-- short-circuit type class inference
instance : TopologicalAddGroup β := by infer_instance
instance : TopologicalRing β := inferInstance
instance : TopologicalDivisionRing β := inferInstance
instance : ProperSpace β where
isCompact_closedBall x r := by
| rw [Real.closedBall_eq_Icc] | instance : ProperSpace β where
isCompact_closedBall x r := by
| Mathlib.Topology.Instances.Real.53_0.cAejORboOY2cNtK | instance : ProperSpace β where
isCompact_closedBall x r | Mathlib_Topology_Instances_Real |
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
x r : β
β’ IsCompact (Icc (x - r) (x + r)) | /-
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, Mario Carneiro
-/
import Mathlib.Topology.Algebra.UniformMulAction
import Mathlib.Topology.Algebra.Star
import Mathlib.Topology.Algebra.Order.Field
import Mathlib.Algebra.Periodic
import Mathlib.Topology.Instances.Int
#align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd"
/-!
# Topological properties of β
-/
noncomputable section
open Classical Filter Int Metric Set TopologicalSpace Bornology
open scoped Topology Uniformity Interval
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
instance : NoncompactSpace β := Int.closedEmbedding_coe_real.noncompactSpace
theorem Real.uniformContinuous_add : UniformContinuous fun p : β Γ β => p.1 + p.2 :=
Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 =>
let β¨Ξ΄, Ξ΄0, HΞ΄β© := rat_add_continuous_lemma abs Ξ΅0
β¨Ξ΄, Ξ΄0, fun h =>
let β¨hβ, hββ© := max_lt_iff.1 h
HΞ΄ hβ hββ©
#align real.uniform_continuous_add Real.uniformContinuous_add
theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg β _) :=
Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 =>
β¨_, Ξ΅0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using hβ©
#align real.uniform_continuous_neg Real.uniformContinuous_neg
instance : ContinuousStar β := β¨continuous_idβ©
instance : UniformAddGroup β :=
UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg
-- short-circuit type class inference
instance : TopologicalAddGroup β := by infer_instance
instance : TopologicalRing β := inferInstance
instance : TopologicalDivisionRing β := inferInstance
instance : ProperSpace β where
isCompact_closedBall x r := by
rw [Real.closedBall_eq_Icc]
| apply isCompact_Icc | instance : ProperSpace β where
isCompact_closedBall x r := by
rw [Real.closedBall_eq_Icc]
| Mathlib.Topology.Instances.Real.53_0.cAejORboOY2cNtK | instance : ProperSpace β where
isCompact_closedBall x r | Mathlib_Topology_Instances_Real |
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
β’ β u β β a, β b, β (_ : a < b), {Ioo βa βb}, IsOpen 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, Mario Carneiro
-/
import Mathlib.Topology.Algebra.UniformMulAction
import Mathlib.Topology.Algebra.Star
import Mathlib.Topology.Algebra.Order.Field
import Mathlib.Algebra.Periodic
import Mathlib.Topology.Instances.Int
#align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd"
/-!
# Topological properties of β
-/
noncomputable section
open Classical Filter Int Metric Set TopologicalSpace Bornology
open scoped Topology Uniformity Interval
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
instance : NoncompactSpace β := Int.closedEmbedding_coe_real.noncompactSpace
theorem Real.uniformContinuous_add : UniformContinuous fun p : β Γ β => p.1 + p.2 :=
Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 =>
let β¨Ξ΄, Ξ΄0, HΞ΄β© := rat_add_continuous_lemma abs Ξ΅0
β¨Ξ΄, Ξ΄0, fun h =>
let β¨hβ, hββ© := max_lt_iff.1 h
HΞ΄ hβ hββ©
#align real.uniform_continuous_add Real.uniformContinuous_add
theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg β _) :=
Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 =>
β¨_, Ξ΅0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using hβ©
#align real.uniform_continuous_neg Real.uniformContinuous_neg
instance : ContinuousStar β := β¨continuous_idβ©
instance : UniformAddGroup β :=
UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg
-- short-circuit type class inference
instance : TopologicalAddGroup β := by infer_instance
instance : TopologicalRing β := inferInstance
instance : TopologicalDivisionRing β := inferInstance
instance : ProperSpace β where
isCompact_closedBall x r := by
rw [Real.closedBall_eq_Icc]
apply isCompact_Icc
instance : SecondCountableTopology β := secondCountable_of_proper
theorem Real.isTopologicalBasis_Ioo_rat :
@IsTopologicalBasis β _ (β (a : β) (b : β) (_ : a < b), {Ioo (a : β) b}) :=
isTopologicalBasis_of_isOpen_of_nhds (by | simp (config := { contextual := true }) [isOpen_Ioo] | theorem Real.isTopologicalBasis_Ioo_rat :
@IsTopologicalBasis β _ (β (a : β) (b : β) (_ : a < b), {Ioo (a : β) b}) :=
isTopologicalBasis_of_isOpen_of_nhds (by | Mathlib.Topology.Instances.Real.60_0.cAejORboOY2cNtK | theorem Real.isTopologicalBasis_Ioo_rat :
@IsTopologicalBasis β _ (β (a : β) (b : β) (_ : a < b), {Ioo (a : β) b}) | Mathlib_Topology_Instances_Real |
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
a : β
v : Set β
hav : a β v
hv : IsOpen v
l u : β
hl : l < a
hu : a < u
h : Ioo l u β v
q : β
hlq : l < βq
hqa : βq < a
p : β
hap : a < βp
hpu : βp < u
β’ Ioo βq βp β β a, β b, β (_ : a < b), {Ioo βa β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, Mario Carneiro
-/
import Mathlib.Topology.Algebra.UniformMulAction
import Mathlib.Topology.Algebra.Star
import Mathlib.Topology.Algebra.Order.Field
import Mathlib.Algebra.Periodic
import Mathlib.Topology.Instances.Int
#align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd"
/-!
# Topological properties of β
-/
noncomputable section
open Classical Filter Int Metric Set TopologicalSpace Bornology
open scoped Topology Uniformity Interval
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
instance : NoncompactSpace β := Int.closedEmbedding_coe_real.noncompactSpace
theorem Real.uniformContinuous_add : UniformContinuous fun p : β Γ β => p.1 + p.2 :=
Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 =>
let β¨Ξ΄, Ξ΄0, HΞ΄β© := rat_add_continuous_lemma abs Ξ΅0
β¨Ξ΄, Ξ΄0, fun h =>
let β¨hβ, hββ© := max_lt_iff.1 h
HΞ΄ hβ hββ©
#align real.uniform_continuous_add Real.uniformContinuous_add
theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg β _) :=
Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 =>
β¨_, Ξ΅0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using hβ©
#align real.uniform_continuous_neg Real.uniformContinuous_neg
instance : ContinuousStar β := β¨continuous_idβ©
instance : UniformAddGroup β :=
UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg
-- short-circuit type class inference
instance : TopologicalAddGroup β := by infer_instance
instance : TopologicalRing β := inferInstance
instance : TopologicalDivisionRing β := inferInstance
instance : ProperSpace β where
isCompact_closedBall x r := by
rw [Real.closedBall_eq_Icc]
apply isCompact_Icc
instance : SecondCountableTopology β := secondCountable_of_proper
theorem Real.isTopologicalBasis_Ioo_rat :
@IsTopologicalBasis β _ (β (a : β) (b : β) (_ : a < b), {Ioo (a : β) b}) :=
isTopologicalBasis_of_isOpen_of_nhds (by simp (config := { contextual := true }) [isOpen_Ioo])
fun a v hav hv =>
let β¨l, u, β¨hl, huβ©, hβ© := mem_nhds_iff_exists_Ioo_subset.mp (IsOpen.mem_nhds hv hav)
let β¨q, hlq, hqaβ© := exists_rat_btwn hl
let β¨p, hap, hpuβ© := exists_rat_btwn hu
β¨Ioo q p, by
| simp only [mem_iUnion] | theorem Real.isTopologicalBasis_Ioo_rat :
@IsTopologicalBasis β _ (β (a : β) (b : β) (_ : a < b), {Ioo (a : β) b}) :=
isTopologicalBasis_of_isOpen_of_nhds (by simp (config := { contextual := true }) [isOpen_Ioo])
fun a v hav hv =>
let β¨l, u, β¨hl, huβ©, hβ© := mem_nhds_iff_exists_Ioo_subset.mp (IsOpen.mem_nhds hv hav)
let β¨q, hlq, hqaβ© := exists_rat_btwn hl
let β¨p, hap, hpuβ© := exists_rat_btwn hu
β¨Ioo q p, by
| Mathlib.Topology.Instances.Real.60_0.cAejORboOY2cNtK | theorem Real.isTopologicalBasis_Ioo_rat :
@IsTopologicalBasis β _ (β (a : β) (b : β) (_ : a < b), {Ioo (a : β) b}) | Mathlib_Topology_Instances_Real |
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
a : β
v : Set β
hav : a β v
hv : IsOpen v
l u : β
hl : l < a
hu : a < u
h : Ioo l u β v
q : β
hlq : l < βq
hqa : βq < a
p : β
hap : a < βp
hpu : βp < u
β’ β i i_1, β (_ : i < i_1), Ioo βq βp β {Ioo βi β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, Mario Carneiro
-/
import Mathlib.Topology.Algebra.UniformMulAction
import Mathlib.Topology.Algebra.Star
import Mathlib.Topology.Algebra.Order.Field
import Mathlib.Algebra.Periodic
import Mathlib.Topology.Instances.Int
#align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd"
/-!
# Topological properties of β
-/
noncomputable section
open Classical Filter Int Metric Set TopologicalSpace Bornology
open scoped Topology Uniformity Interval
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
instance : NoncompactSpace β := Int.closedEmbedding_coe_real.noncompactSpace
theorem Real.uniformContinuous_add : UniformContinuous fun p : β Γ β => p.1 + p.2 :=
Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 =>
let β¨Ξ΄, Ξ΄0, HΞ΄β© := rat_add_continuous_lemma abs Ξ΅0
β¨Ξ΄, Ξ΄0, fun h =>
let β¨hβ, hββ© := max_lt_iff.1 h
HΞ΄ hβ hββ©
#align real.uniform_continuous_add Real.uniformContinuous_add
theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg β _) :=
Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 =>
β¨_, Ξ΅0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using hβ©
#align real.uniform_continuous_neg Real.uniformContinuous_neg
instance : ContinuousStar β := β¨continuous_idβ©
instance : UniformAddGroup β :=
UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg
-- short-circuit type class inference
instance : TopologicalAddGroup β := by infer_instance
instance : TopologicalRing β := inferInstance
instance : TopologicalDivisionRing β := inferInstance
instance : ProperSpace β where
isCompact_closedBall x r := by
rw [Real.closedBall_eq_Icc]
apply isCompact_Icc
instance : SecondCountableTopology β := secondCountable_of_proper
theorem Real.isTopologicalBasis_Ioo_rat :
@IsTopologicalBasis β _ (β (a : β) (b : β) (_ : a < b), {Ioo (a : β) b}) :=
isTopologicalBasis_of_isOpen_of_nhds (by simp (config := { contextual := true }) [isOpen_Ioo])
fun a v hav hv =>
let β¨l, u, β¨hl, huβ©, hβ© := mem_nhds_iff_exists_Ioo_subset.mp (IsOpen.mem_nhds hv hav)
let β¨q, hlq, hqaβ© := exists_rat_btwn hl
let β¨p, hap, hpuβ© := exists_rat_btwn hu
β¨Ioo q p, by
simp only [mem_iUnion]
| exact β¨q, p, Rat.cast_lt.1 <| hqa.trans hap, rflβ© | theorem Real.isTopologicalBasis_Ioo_rat :
@IsTopologicalBasis β _ (β (a : β) (b : β) (_ : a < b), {Ioo (a : β) b}) :=
isTopologicalBasis_of_isOpen_of_nhds (by simp (config := { contextual := true }) [isOpen_Ioo])
fun a v hav hv =>
let β¨l, u, β¨hl, huβ©, hβ© := mem_nhds_iff_exists_Ioo_subset.mp (IsOpen.mem_nhds hv hav)
let β¨q, hlq, hqaβ© := exists_rat_btwn hl
let β¨p, hap, hpuβ© := exists_rat_btwn hu
β¨Ioo q p, by
simp only [mem_iUnion]
| Mathlib.Topology.Instances.Real.60_0.cAejORboOY2cNtK | theorem Real.isTopologicalBasis_Ioo_rat :
@IsTopologicalBasis β _ (β (a : β) (b : β) (_ : a < b), {Ioo (a : β) b}) | Mathlib_Topology_Instances_Real |
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
β’ cobounded β = atBot β atTop | /-
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, Mario Carneiro
-/
import Mathlib.Topology.Algebra.UniformMulAction
import Mathlib.Topology.Algebra.Star
import Mathlib.Topology.Algebra.Order.Field
import Mathlib.Algebra.Periodic
import Mathlib.Topology.Instances.Int
#align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd"
/-!
# Topological properties of β
-/
noncomputable section
open Classical Filter Int Metric Set TopologicalSpace Bornology
open scoped Topology Uniformity Interval
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
instance : NoncompactSpace β := Int.closedEmbedding_coe_real.noncompactSpace
theorem Real.uniformContinuous_add : UniformContinuous fun p : β Γ β => p.1 + p.2 :=
Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 =>
let β¨Ξ΄, Ξ΄0, HΞ΄β© := rat_add_continuous_lemma abs Ξ΅0
β¨Ξ΄, Ξ΄0, fun h =>
let β¨hβ, hββ© := max_lt_iff.1 h
HΞ΄ hβ hββ©
#align real.uniform_continuous_add Real.uniformContinuous_add
theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg β _) :=
Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 =>
β¨_, Ξ΅0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using hβ©
#align real.uniform_continuous_neg Real.uniformContinuous_neg
instance : ContinuousStar β := β¨continuous_idβ©
instance : UniformAddGroup β :=
UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg
-- short-circuit type class inference
instance : TopologicalAddGroup β := by infer_instance
instance : TopologicalRing β := inferInstance
instance : TopologicalDivisionRing β := inferInstance
instance : ProperSpace β where
isCompact_closedBall x r := by
rw [Real.closedBall_eq_Icc]
apply isCompact_Icc
instance : SecondCountableTopology β := secondCountable_of_proper
theorem Real.isTopologicalBasis_Ioo_rat :
@IsTopologicalBasis β _ (β (a : β) (b : β) (_ : a < b), {Ioo (a : β) b}) :=
isTopologicalBasis_of_isOpen_of_nhds (by simp (config := { contextual := true }) [isOpen_Ioo])
fun a v hav hv =>
let β¨l, u, β¨hl, huβ©, hβ© := mem_nhds_iff_exists_Ioo_subset.mp (IsOpen.mem_nhds hv hav)
let β¨q, hlq, hqaβ© := exists_rat_btwn hl
let β¨p, hap, hpuβ© := exists_rat_btwn hu
β¨Ioo q p, by
simp only [mem_iUnion]
exact β¨q, p, Rat.cast_lt.1 <| hqa.trans hap, rflβ©, β¨hqa, hapβ©, fun a' β¨hqa', ha'pβ© =>
h β¨hlq.trans hqa', ha'p.trans hpuβ©β©
#align real.is_topological_basis_Ioo_rat Real.isTopologicalBasis_Ioo_rat
@[simp]
theorem Real.cobounded_eq : cobounded β = atBot β atTop := by
| simp only [β comap_dist_right_atTop (0 : β), Real.dist_eq, sub_zero, comap_abs_atTop] | @[simp]
theorem Real.cobounded_eq : cobounded β = atBot β atTop := by
| Mathlib.Topology.Instances.Real.73_0.cAejORboOY2cNtK | @[simp]
theorem Real.cobounded_eq : cobounded β = atBot β atTop | Mathlib_Topology_Instances_Real |
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
β’ cocompact β = atBot β atTop | /-
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, Mario Carneiro
-/
import Mathlib.Topology.Algebra.UniformMulAction
import Mathlib.Topology.Algebra.Star
import Mathlib.Topology.Algebra.Order.Field
import Mathlib.Algebra.Periodic
import Mathlib.Topology.Instances.Int
#align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd"
/-!
# Topological properties of β
-/
noncomputable section
open Classical Filter Int Metric Set TopologicalSpace Bornology
open scoped Topology Uniformity Interval
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
instance : NoncompactSpace β := Int.closedEmbedding_coe_real.noncompactSpace
theorem Real.uniformContinuous_add : UniformContinuous fun p : β Γ β => p.1 + p.2 :=
Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 =>
let β¨Ξ΄, Ξ΄0, HΞ΄β© := rat_add_continuous_lemma abs Ξ΅0
β¨Ξ΄, Ξ΄0, fun h =>
let β¨hβ, hββ© := max_lt_iff.1 h
HΞ΄ hβ hββ©
#align real.uniform_continuous_add Real.uniformContinuous_add
theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg β _) :=
Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 =>
β¨_, Ξ΅0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using hβ©
#align real.uniform_continuous_neg Real.uniformContinuous_neg
instance : ContinuousStar β := β¨continuous_idβ©
instance : UniformAddGroup β :=
UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg
-- short-circuit type class inference
instance : TopologicalAddGroup β := by infer_instance
instance : TopologicalRing β := inferInstance
instance : TopologicalDivisionRing β := inferInstance
instance : ProperSpace β where
isCompact_closedBall x r := by
rw [Real.closedBall_eq_Icc]
apply isCompact_Icc
instance : SecondCountableTopology β := secondCountable_of_proper
theorem Real.isTopologicalBasis_Ioo_rat :
@IsTopologicalBasis β _ (β (a : β) (b : β) (_ : a < b), {Ioo (a : β) b}) :=
isTopologicalBasis_of_isOpen_of_nhds (by simp (config := { contextual := true }) [isOpen_Ioo])
fun a v hav hv =>
let β¨l, u, β¨hl, huβ©, hβ© := mem_nhds_iff_exists_Ioo_subset.mp (IsOpen.mem_nhds hv hav)
let β¨q, hlq, hqaβ© := exists_rat_btwn hl
let β¨p, hap, hpuβ© := exists_rat_btwn hu
β¨Ioo q p, by
simp only [mem_iUnion]
exact β¨q, p, Rat.cast_lt.1 <| hqa.trans hap, rflβ©, β¨hqa, hapβ©, fun a' β¨hqa', ha'pβ© =>
h β¨hlq.trans hqa', ha'p.trans hpuβ©β©
#align real.is_topological_basis_Ioo_rat Real.isTopologicalBasis_Ioo_rat
@[simp]
theorem Real.cobounded_eq : cobounded β = atBot β atTop := by
simp only [β comap_dist_right_atTop (0 : β), Real.dist_eq, sub_zero, comap_abs_atTop]
@[simp]
theorem Real.cocompact_eq : cocompact β = atBot β atTop := by
| rw [β cobounded_eq_cocompact, cobounded_eq] | @[simp]
theorem Real.cocompact_eq : cocompact β = atBot β atTop := by
| Mathlib.Topology.Instances.Real.77_0.cAejORboOY2cNtK | @[simp]
theorem Real.cocompact_eq : cocompact β = atBot β atTop | Mathlib_Topology_Instances_Real |
Subsets and Splits