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
No community queries yet
The top public SQL queries from the community will appear here once available.