Datasets:
Tasks:
Text Generation
Modalities:
Text
Sub-tasks:
language-modeling
Languages:
English
Size:
100K - 1M
License:
File size: 10,406 Bytes
4365a98 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
/-
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 analysis.convex.function
/-!
# 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.
-/
variables {π : Type*} [linear_ordered_field π] {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]`. -/
lemma convex_on.slope_mono_adjacent (hf : convex_on π s f)
{x y z : π} (hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
begin
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),
{ ring_nf at this β’, linarith },
set a := (z - y) / (z - x),
set b := (y - x) / (z - x),
have hy : a β’ x + b β’ z = y, by { field_simp, rw div_eq_iff; [ring, linarith] },
have key, from
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 div_eq_iff; [ring, linarith] }),
rw hy at key,
replace key := mul_le_mul_of_nonneg_left key hxz.le,
field_simp [hxy.ne', hyz.ne', hxz.ne', mul_comm (z - x) _] at key β’,
rw div_le_div_right,
{ linarith },
{ nlinarith }
end
/-- 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]`. -/
lemma concave_on.slope_anti_adjacent (hf : concave_on π s f) {x y z : π} (hx : x β s)
(hz : z β s) (hxy : x < y) (hyz : y < z) :
(f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
begin
rw [βneg_le_neg_iff, βneg_sub_neg (f x), βneg_sub_neg (f y)],
simp_rw [βpi.neg_apply, βneg_div, neg_sub],
exact convex_on.slope_mono_adjacent hf.neg hx hz hxy hyz,
end
/-- 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]`. -/
lemma strict_convex_on.slope_strict_mono_adjacent (hf : strict_convex_on π s f)
{x y z : π} (hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) :=
begin
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),
{ ring_nf at this β’, linarith },
set a := (z - y) / (z - x),
set b := (y - x) / (z - x),
have hy : a β’ x + b β’ z = y, by { field_simp, rw div_eq_iff; [ring, linarith] },
have key, from
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1, by { field_simp, rw div_eq_iff; [ring, linarith] }),
rw hy at key,
replace key := mul_lt_mul_of_pos_left key hxz,
field_simp [hxy.ne', hyz.ne', hxz.ne', mul_comm (z - x) _] at key β’,
rw div_lt_div_right,
{ linarith },
{ nlinarith }
end
/-- 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]`. -/
lemma strict_concave_on.slope_anti_adjacent (hf : strict_concave_on π s f)
{x y z : π} (hx : x β s) (hz : z β s) (hxy : x < y) (hyz : y < z) :
(f z - f y) / (z - y) < (f y - f x) / (y - x) :=
begin
rw [βneg_lt_neg_iff, βneg_sub_neg (f x), βneg_sub_neg (f y)],
simp_rw [βpi.neg_apply, βneg_div, neg_sub],
exact strict_convex_on.slope_strict_mono_adjacent hf.neg hx hz hxy hyz,
end
/-- 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. -/
lemma convex_on_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)) :
convex_on π s f :=
linear_order.convex_on_of_lt hs
begin
assume x z hx hz hxz a b ha hb hab,
let y := a * x + b * z,
have hxy : x < y,
{ rw [β one_mul x, β hab, add_mul],
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ },
have hyz : y < z,
{ rw [β one_mul z, β hab, add_mul],
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ },
have : (f y - f x) * (z - y) β€ (f z - f y) * (y - x),
from (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz),
have hxz : 0 < z - x, from sub_pos.2 (hxy.trans hyz),
have ha : (z - y) / (z - x) = a,
{ rw [eq_comm, β sub_eq_iff_eq_add'] at hab,
simp_rw [div_eq_iff hxz.ne', y, βhab], ring },
have hb : (y - x) / (z - x) = b,
{ rw [eq_comm, β sub_eq_iff_eq_add] at hab,
simp_rw [div_eq_iff hxz.ne', y, β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,
end
/-- 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. -/
lemma concave_on_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)) : concave_on π s f :=
begin
rw βneg_convex_on_iff,
refine convex_on_of_slope_mono_adjacent hs (Ξ» x y z 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,
end
/-- 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. -/
lemma strict_convex_on_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)) :
strict_convex_on π s f :=
linear_order.strict_convex_on_of_lt hs
begin
assume x z hx hz hxz a b ha hb hab,
let y := a * x + b * z,
have hxy : x < y,
{ rw [β one_mul x, β hab, add_mul],
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ },
have hyz : y < z,
{ rw [β one_mul z, β hab, add_mul],
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ },
have : (f y - f x) * (z - y) < (f z - f y) * (y - x),
from (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz),
have hxz : 0 < z - x, from sub_pos.2 (hxy.trans hyz),
have ha : (z - y) / (z - x) = a,
{ rw [eq_comm, β sub_eq_iff_eq_add'] at hab,
simp_rw [div_eq_iff hxz.ne', y, βhab], ring },
have hb : (y - x) / (z - x) = b,
{ rw [eq_comm, β sub_eq_iff_eq_add] at hab,
simp_rw [div_eq_iff hxz.ne', y, β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,
end
/-- 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.
-/
lemma strict_concave_on_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)) : strict_concave_on π s f :=
begin
rw βneg_strict_convex_on_iff,
refine strict_convex_on_of_slope_strict_mono_adjacent hs (Ξ» x y z 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,
end
/-- 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]`. -/
lemma convex_on_iff_slope_mono_adjacent :
convex_on π s f β convex π s β§
β β¦x y z : πβ¦, x β s β z β s β x < y β y < z β
(f y - f x) / (y - x) β€ (f z - f y) / (z - y) :=
β¨Ξ» h, β¨h.1, Ξ» x y z, h.slope_mono_adjacentβ©, Ξ» h, convex_on_of_slope_mono_adjacent h.1 h.2β©
/-- 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]`. -/
lemma concave_on_iff_slope_anti_adjacent :
concave_on π s f β convex π s β§
β β¦x y z : πβ¦, x β s β z β s β x < y β y < z β
(f z - f y) / (z - y) β€ (f y - f x) / (y - x) :=
β¨Ξ» h, β¨h.1, Ξ» x y z, h.slope_anti_adjacentβ©, Ξ» h, concave_on_of_slope_anti_adjacent h.1 h.2β©
/-- 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]`. -/
lemma strict_convex_on_iff_slope_strict_mono_adjacent :
strict_convex_on π s f β convex π s β§
β β¦x y z : πβ¦, x β s β z β s β x < y β y < z β
(f y - f x) / (y - x) < (f z - f y) / (z - y) :=
β¨Ξ» h, β¨h.1, Ξ» x y z, h.slope_strict_mono_adjacentβ©,
Ξ» h, strict_convex_on_of_slope_strict_mono_adjacent h.1 h.2β©
/-- 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]`. -/
lemma strict_concave_on_iff_slope_strict_anti_adjacent :
strict_concave_on π s f β convex π s β§
β β¦x y z : πβ¦, x β s β z β s β x < y β y < z β
(f z - f y) / (z - y) < (f y - f x) / (y - x) :=
β¨Ξ» h, β¨h.1, Ξ» x y z, h.slope_anti_adjacentβ©,
Ξ» h, strict_concave_on_of_slope_strict_anti_adjacent h.1 h.2β©
|