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
|
---|---|---|---|---|---|---|
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConvexOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : 0 < y - x
hyz : 0 < z - y
hxz : 0 < z - x
hxz' : x β z
a : π := (z - y) / (z - x)
b : π := (y - x) / (z - x)
β’ a β’ x + b β’ 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 | /-- 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 | Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ | /-- 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) | 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 : 0 < y - x
hyz : 0 < z - y
hxz : 0 < z - x
hxz' : x β z
a : π := (z - y) / (z - x)
b : π := (y - x) / (z - x)
β’ (z - y) * x + (y - x) * 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 | /-- 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; | Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ | /-- 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) | 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 : 0 < y - x
hyz : 0 < z - y
hxz : 0 < z - x
hxz' : x β z
a : π := (z - y) / (z - x)
b : π := (y - x) / (z - x)
hy : a β’ x + b β’ z = y
β’ f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (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) | /-- 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
| Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ | /-- 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) | 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 : 0 < y - x
hyz : 0 < z - y
hxz : 0 < z - x
hxz' : x β z
a : π := (z - y) / (z - x)
b : π := (y - x) / (z - x)
hy : a β’ x + b β’ z = y
β’ a + b = 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 | /-- 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 | Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ | /-- 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) | 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 : 0 < y - x
hyz : 0 < z - y
hxz : 0 < z - x
hxz' : x β z
a : π := (z - y) / (z - x)
b : π := (y - x) / (z - x)
hy : a β’ x + b β’ z = y
key : f (((z - y) / (z - x)) β’ x + ((y - x) / (z - x)) β’ z) < ((z - y) / (z - x)) β’ f x + ((y - x) / (z - x)) β’ f z
β’ f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (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 | /-- 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)
| Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ | /-- 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) | 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 : 0 < y - x
hyz : 0 < z - y
hxz : 0 < z - x
hxz' : x β z
a : π := (z - y) / (z - x)
b : π := (y - x) / (z - x)
hy : a β’ x + b β’ z = y
key : f y < ((z - y) / (z - x)) β’ f x + ((y - x) / (z - x)) β’ f z
β’ f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (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 | /-- 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
| Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ | /-- 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) | 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 : 0 < y - x
hyz : 0 < z - y
hxz : 0 < z - x
hxz' : x β z
a : π := (z - y) / (z - x)
b : π := (y - x) / (z - x)
hy : a β’ x + b β’ z = y
key : (z - x) * f y < (z - x) * (((z - y) / (z - x)) β’ f x + ((y - x) / (z - x)) β’ f z)
β’ f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (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 β’ | /-- 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
| Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ | /-- 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) | 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 : 0 < y - x
hyz : 0 < z - y
hxz : 0 < z - x
hxz' : x β z
a : π := (z - y) / (z - x)
b : π := (y - x) / (z - x)
hy : a β’ x + b β’ z = y
key : f y * (z - x) < (z - y) * f x + (y - x) * f z
β’ (f y * (z - y) + f y * (y - x)) / ((y - x) * (z - y)) < (f x * (z - y) + f z * (y - x)) / ((y - x) * (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] | /-- 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 β’
| Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ | /-- 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) | 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 : 0 < y - x
hyz : 0 < z - y
hxz : 0 < z - x
hxz' : x β z
a : π := (z - y) / (z - x)
b : π := (y - x) / (z - x)
hy : a β’ x + b β’ z = y
key : f y * (z - x) < (z - y) * f x + (y - x) * f z
β’ f y * (z - y) + f y * (y - x) < f x * (z - y) + f z * (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 | /-- 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]
Β· | Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ | /-- 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) | 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 : 0 < y - x
hyz : 0 < z - y
hxz : 0 < z - x
hxz' : x β z
a : π := (z - y) / (z - x)
b : π := (y - x) / (z - x)
hy : a β’ x + b β’ z = y
key : f y * (z - x) < (z - y) * f x + (y - x) * f z
β’ 0 < (y - x) * (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 | /-- 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
Β· | Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ | /-- 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) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
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) | /-
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) | /-- 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
| Mathlib.Analysis.Convex.Slope.83_0.2UqTeSfXEWgn9kZ | /-- 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) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConcaveOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
this : -(((-f) z - (-f) y) / (z - y)) < -(((-f) y - (-f) x) / (y - x))
β’ (f z - f y) / (z - y) < (f y - 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 | /-- 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)
| Mathlib.Analysis.Convex.Slope.83_0.2UqTeSfXEWgn9kZ | /-- 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) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : StrictConcaveOn π s f
x y z : π
hx : x β s
hz : z β s
hxy : x < y
hyz : y < z
this : (f z - f y) / (z - y) < (f y - f x) / (y - x)
β’ (f z - f y) / (z - y) < (f y - 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 | /-- 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
| Mathlib.Analysis.Convex.Slope.83_0.2UqTeSfXEWgn9kZ | /-- 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) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
β’ f (a β’ x + b β’ z) β€ a β’ f x + b β’ 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 | /-- 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
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
β’ f (a β’ x + b β’ z) β€ a β’ f x + b β’ 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) _ | /-- 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
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
β’ x < 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] | /-- 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
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
β’ a * x + b * x < 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) _ | /-- 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]
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
β’ f (a β’ x + b β’ z) β€ a β’ f x + b β’ 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) _ | /-- 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) _
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
β’ y < 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] | /-- 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
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
β’ y < a * z + b * 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) _ | /-- 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]
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
hyz : y < z
β’ f (a β’ x + b β’ z) β€ a β’ f x + b β’ 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) | /-- 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) _
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) β€ (f z - f y) * (y - x)
β’ f (a β’ x + b β’ z) β€ a β’ f x + b β’ 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) | /-- 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)
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) β€ (f z - f y) * (y - x)
hxz : 0 < z - x
β’ f (a β’ x + b β’ z) β€ a β’ f x + b β’ 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 | /-- 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)
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) β€ (f z - f y) * (y - x)
hxz : 0 < z - x
β’ (z - y) / (z - 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 | /-- 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
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : 1 - a = b
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) β€ (f z - f y) * (y - x)
hxz : 0 < z - x
β’ (z - y) / (z - 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] | /-- 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
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : 1 - a = b
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) β€ (f z - f y) * (y - x)
hxz : 0 < z - x
β’ z - (a * x + (1 - a) * z) = a * (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 | /-- 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]
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
haβ : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) β€ (f z - f y) * (y - x)
hxz : 0 < z - x
ha : (z - y) / (z - x) = a
β’ f (a β’ x + b β’ z) β€ a β’ f x + b β’ 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 | /-- 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
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
haβ : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) β€ (f z - f y) * (y - x)
hxz : 0 < z - x
ha : (z - y) / (z - x) = a
β’ (y - x) / (z - x) = b | /-
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 | /-- 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
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
haβ : 0 < a
hb : 0 < b
hab : 1 - b = a
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) β€ (f z - f y) * (y - x)
hxz : 0 < z - x
ha : (z - y) / (z - x) = a
β’ (y - x) / (z - x) = b | /-
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] | /-- 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
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
haβ : 0 < a
hb : 0 < b
hab : 1 - b = a
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) β€ (f z - f y) * (y - x)
hxz : 0 < z - x
ha : (z - y) / (z - x) = a
β’ (1 - b) * x + b * z - x = b * (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 | /-- 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]
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
haβ : 0 < a
hbβ : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) β€ (f z - f y) * (y - x)
hxz : 0 < z - x
ha : (z - y) / (z - x) = a
hb : (y - x) / (z - x) = b
β’ f (a β’ x + b β’ z) β€ a β’ f x + b β’ 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 | /-- 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
| Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
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 | /-
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] | /-- 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
| Mathlib.Analysis.Convex.Slope.124_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)
β’ ConvexOn π s (-f) | /-
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 => _ | /-- 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]
| Mathlib.Analysis.Convex.Slope.124_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)
xβ yβ zβ : π
hx : xβ β s
hz : zβ β s
hxy : xβ < yβ
hyz : yβ < zβ
β’ ((-f) yβ - (-f) xβ) / (yβ - 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] | /-- 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 => _
| Mathlib.Analysis.Convex.Slope.124_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)
xβ yβ zβ : π
hx : xβ β s
hz : zβ β s
hxy : xβ < yβ
hyz : yβ < zβ
β’ -(((-f) zβ - (-f) yβ) / (zβ - yβ)) β€ -(((-f) yβ - (-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] | /-- 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]
| Mathlib.Analysis.Convex.Slope.124_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f z - f y) / (z - y) β€ (f y - f x) / (y - x)
xβ yβ zβ : π
hx : xβ β s
hz : zβ β s
hxy : xβ < yβ
hyz : yβ < zβ
β’ (f zβ - f yβ) / (zβ - yβ) β€ (f yβ - 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 | /-- 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]
| Mathlib.Analysis.Convex.Slope.124_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
β’ f (a β’ x + b β’ z) < a β’ f x + b β’ 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 | /-- 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
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
β’ f (a β’ x + b β’ z) < a β’ f x + b β’ 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) _ | /-- 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
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
β’ x < 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] | /-- 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
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
β’ a * x + b * x < 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) _ | /-- 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]
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
β’ f (a β’ x + b β’ z) < a β’ f x + b β’ 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) _ | /-- 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) _
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
β’ y < 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] | /-- 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
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
β’ y < a * z + b * 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) _ | /-- 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]
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
hyz : y < z
β’ f (a β’ x + b β’ z) < a β’ f x + b β’ 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) | /-- 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) _
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxz : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) < (f z - f y) * (y - x)
β’ f (a β’ x + b β’ z) < a β’ f x + b β’ 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) | /-- 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)
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) < (f z - f y) * (y - x)
hxz : 0 < z - x
β’ f (a β’ x + b β’ z) < a β’ f x + b β’ 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 | /-- 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)
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) < (f z - f y) * (y - x)
hxz : 0 < z - x
β’ (z - y) / (z - 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 | /-- 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
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : 1 - a = b
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) < (f z - f y) * (y - x)
hxz : 0 < z - x
β’ (z - y) / (z - 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] | /-- 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
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
ha : 0 < a
hb : 0 < b
hab : 1 - a = b
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) < (f z - f y) * (y - x)
hxz : 0 < z - x
β’ z - (a * x + (1 - a) * z) = a * (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 | /-- 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]
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
haβ : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) < (f z - f y) * (y - x)
hxz : 0 < z - x
ha : (z - y) / (z - x) = a
β’ f (a β’ x + b β’ z) < a β’ f x + b β’ 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 | /-- 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
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
haβ : 0 < a
hb : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) < (f z - f y) * (y - x)
hxz : 0 < z - x
ha : (z - y) / (z - x) = a
β’ (y - x) / (z - x) = b | /-
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 | /-- 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
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
haβ : 0 < a
hb : 0 < b
hab : 1 - b = a
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) < (f z - f y) * (y - x)
hxz : 0 < z - x
ha : (z - y) / (z - x) = a
β’ (y - x) / (z - x) = b | /-
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] | /-- 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
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
haβ : 0 < a
hb : 0 < b
hab : 1 - b = a
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) < (f z - f y) * (y - x)
hxz : 0 < z - x
ha : (z - y) / (z - x) = a
β’ (1 - b) * x + b * z - x = b * (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 | /-- 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]
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f y - f x) / (y - x) < (f z - f y) / (z - y)
x : π
hx : x β s
z : π
hz : z β s
hxzβ : x < z
a b : π
haβ : 0 < a
hbβ : 0 < b
hab : a + b = 1
y : π := a * x + b * z
hxy : x < y
hyz : y < z
this : (f y - f x) * (z - y) < (f z - f y) * (y - x)
hxz : 0 < z - x
ha : (z - y) / (z - x) = a
hb : (y - x) / (z - x) = b
β’ f (a β’ x + b β’ z) < a β’ f x + b β’ 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 | /-- 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
| Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
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 | /-
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] | /-- 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
| Mathlib.Analysis.Convex.Slope.169_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)
β’ StrictConvexOn π s (-f) | /-
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 => _ | /-- 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]
| Mathlib.Analysis.Convex.Slope.169_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)
xβ yβ zβ : π
hx : xβ β s
hz : zβ β s
hxy : xβ < yβ
hyz : yβ < zβ
β’ ((-f) yβ - (-f) xβ) / (yβ - 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] | /-- 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 => _
| Mathlib.Analysis.Convex.Slope.169_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)
xβ yβ zβ : π
hx : xβ β s
hz : zβ β s
hxy : xβ < yβ
hyz : yβ < zβ
β’ -(((-f) zβ - (-f) yβ) / (zβ - yβ)) < -(((-f) yβ - (-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] | /-- 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]
| Mathlib.Analysis.Convex.Slope.169_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hs : Convex π s
hf : β {x y z : π}, x β s β z β s β x < y β y < z β (f z - f y) / (z - y) < (f y - f x) / (y - x)
xβ yβ zβ : π
hx : xβ β s
hz : zβ β s
hxy : xβ < yβ
hyz : yβ < zβ
β’ (f zβ - f yβ) / (zβ - yβ) < (f yβ - 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 | /-- 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]
| Mathlib.Analysis.Convex.Slope.169_0.2UqTeSfXEWgn9kZ | /-- 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
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 | /-
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 | 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
| Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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 | Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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
| Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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 | Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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
| Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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 | Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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'] | 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
| Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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']
| Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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 | Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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
| Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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 | Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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) := ?_ | 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
| Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
case calc_1
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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) := ?_
Β· | Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
case calc_1.e_a
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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
| Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
case calc_1.e_a
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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
| Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
case calc_2
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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
| Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
case calc_2
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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
| Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
case calc_3
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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
Β· | Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ | 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 | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
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 | 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
| Mathlib.Analysis.Convex.Slope.250_0.2UqTeSfXEWgn9kZ | 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) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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 | Mathlib.Analysis.Convex.Slope.250_0.2UqTeSfXEWgn9kZ | 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) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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
| Mathlib.Analysis.Convex.Slope.250_0.2UqTeSfXEWgn9kZ | 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) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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 | Mathlib.Analysis.Convex.Slope.250_0.2UqTeSfXEWgn9kZ | 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) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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'] | 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
| Mathlib.Analysis.Convex.Slope.250_0.2UqTeSfXEWgn9kZ | 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) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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] | 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']
| Mathlib.Analysis.Convex.Slope.250_0.2UqTeSfXEWgn9kZ | 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) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
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) | /-
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 | 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
| Mathlib.Analysis.Convex.Slope.258_0.2UqTeSfXEWgn9kZ | 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) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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 | Mathlib.Analysis.Convex.Slope.258_0.2UqTeSfXEWgn9kZ | 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) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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
| Mathlib.Analysis.Convex.Slope.258_0.2UqTeSfXEWgn9kZ | 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) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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 | 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 | Mathlib.Analysis.Convex.Slope.258_0.2UqTeSfXEWgn9kZ | 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) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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'] | 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
| Mathlib.Analysis.Convex.Slope.258_0.2UqTeSfXEWgn9kZ | 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) | Mathlib_Analysis_Convex_Slope |
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π 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] | 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']
| Mathlib.Analysis.Convex.Slope.258_0.2UqTeSfXEWgn9kZ | 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) | Mathlib_Analysis_Convex_Slope |
π : 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
β’ (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) | 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
| 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 inl
π : Type u_1
instβ : LinearOrderedField π
s : Set π
f : π β π
hf : ConvexOn π s f
a x : π
ha : a β s
hx : x β s
hxa : x β a
hy : x β s
hya : x β a
hxy : x β€ x
β’ (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 | 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)
Β· | 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
π : 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
β’ (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 | 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
| 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.inl
π : 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 | 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
Β· | 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.inl.inl
π : 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 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 | 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
Β· | 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 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] | 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 <;> | 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 h.e'_4
π : 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 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] | 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 <;> | 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 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 | 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] <;> | 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 h.e'_4
π : 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 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 | 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] <;> | 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.inl.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
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 | 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
Β· | 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 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] | 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
| 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 |
Subsets and Splits