state
stringlengths
0
159k
srcUpToTactic
stringlengths
387
167k
nextTactic
stringlengths
3
9k
declUpToTactic
stringlengths
22
11.5k
declId
stringlengths
38
95
decl
stringlengths
16
1.89k
file_tag
stringlengths
17
73
case h.e'_3 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya✝ : y β‰  a hxy✝ : x ≀ y hxy : x < y hxa : x < a hya : y > a ⊒ -(f x - f a) / -(x - a) = (f a - f x) / (a - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq];
field_simp
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq];
Mathlib.Analysis.Convex.Slope.266_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case inr.inr π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya : y β‰  a hxy✝ : x ≀ y hxy : x < y hxa : x > a ⊒ (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β·
exact hf.secant_mono_aux2 ha hy hxa hxy
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β·
Mathlib.Analysis.Convex.Slope.266_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z ⊒ (z - x) * f y < (z - y) * f x + (y - x) * f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z ⊒ 0 < y - x
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by
linarith
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x ⊒ (z - x) * f y < (z - y) * f x + (y - x) * f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x ⊒ 0 < z - y
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by
linarith
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y ⊒ (z - x) * f y < (z - y) * f x + (y - x) * f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y ⊒ 0 < z - x
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by
linarith
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ⊒ (z - x) * f y < (z - y) * f x + (y - x) * f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith
rw [← lt_div_iff' hxz']
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ⊒ f y < ((z - y) * f x + (y - x) * f z) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz']
have ha : 0 < (z - y) / (z - x) := by positivity
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz']
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ⊒ 0 < (z - y) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by
positivity
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 < (z - y) / (z - x) ⊒ f y < ((z - y) * f x + (y - x) * f z) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity
have hb : 0 < (y - x) / (z - x) := by positivity
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 < (z - y) / (z - x) ⊒ 0 < (y - x) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by
positivity
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 < (z - y) / (z - x) hb : 0 < (y - x) / (z - x) ⊒ f y < ((z - y) * f x + (y - x) * f z) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity
calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 < (z - y) / (z - x) hb : 0 < (y - x) / (z - x) ⊒ x β‰  z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by
linarith
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
case calc_1 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 < (z - y) / (z - x) hb : 0 < (y - x) / (z - x) ⊒ f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β·
congr 1
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β·
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
case calc_1.e_a π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 < (z - y) / (z - x) hb : 0 < (y - x) / (z - x) ⊒ y = (z - y) / (z - x) * x + (y - x) / (z - x) * z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1
field_simp
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
case calc_1.e_a π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 < (z - y) / (z - x) hb : 0 < (y - x) / (z - x) ⊒ y * (z - x) = (z - y) * x + (y - x) * z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp
ring
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
case calc_2 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 < (z - y) / (z - x) hb : 0 < (y - x) / (z - x) ⊒ Div.div (z - y) (z - x) + Div.div (y - x) (z - x) = 1
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
case calc_2 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 < (z - y) / (z - x) hb : 0 < (y - x) / (z - x) ⊒ (z - y) / (z - x) + (y - x) / (z - x) = 1
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
case calc_3 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 < (z - y) / (z - x) hb : 0 < (y - x) / (z - x) ⊒ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z = ((z - y) * f x + (y - x) * f z) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β·
field_simp
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β·
Mathlib.Analysis.Convex.Slope.279_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z ⊒ (f y - f x) / (y - x) < (f z - f x) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by
Mathlib.Analysis.Convex.Slope.300_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z ⊒ 0 < y - x
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by
linarith
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by
Mathlib.Analysis.Convex.Slope.300_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x ⊒ (f y - f x) / (y - x) < (f z - f x) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith
Mathlib.Analysis.Convex.Slope.300_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x ⊒ 0 < z - x
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by
linarith
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by
Mathlib.Analysis.Convex.Slope.300_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hxz' : 0 < z - x ⊒ (f y - f x) / (y - x) < (f z - f x) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxy' hxz']
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith
Mathlib.Analysis.Convex.Slope.300_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hxz' : 0 < z - x ⊒ (f y - f x) * (z - x) < (f z - f x) * (y - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz']
Mathlib.Analysis.Convex.Slope.300_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z ⊒ (f z - f x) / (z - x) < (f z - f y) / (z - y)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by
Mathlib.Analysis.Convex.Slope.308_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z ⊒ 0 < z - y
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by
linarith
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by
Mathlib.Analysis.Convex.Slope.308_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hyz' : 0 < z - y ⊒ (f z - f x) / (z - x) < (f z - f y) / (z - y)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith
Mathlib.Analysis.Convex.Slope.308_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hyz' : 0 < z - y ⊒ 0 < z - x
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by
linarith
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by
Mathlib.Analysis.Convex.Slope.308_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hyz' : 0 < z - y hxz' : 0 < z - x ⊒ (f z - f x) / (z - x) < (f z - f y) / (z - y)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith
rw [div_lt_div_iff hxz' hyz']
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith
Mathlib.Analysis.Convex.Slope.308_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hyz' : 0 < z - y hxz' : 0 < z - x ⊒ (f z - f x) * (z - y) < (f z - f y) * (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz']
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz]
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz']
Mathlib.Analysis.Convex.Slope.308_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa : x β‰  a hya : y β‰  a hxy : x < y ⊒ (f x - f a) / (x - a) < (f y - f a) / (y - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by
cases' lt_or_gt_of_ne hxa with hxa hxa
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by
Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case inl π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya : y β‰  a hxy : x < y hxa : x < a ⊒ (f x - f a) / (x - a) < (f y - f a) / (y - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β·
cases' lt_or_gt_of_ne hya with hya hya
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β·
Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case inl.inl π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya✝ : y β‰  a hxy : x < y hxa : x < a hya : y < a ⊒ (f x - f a) / (x - a) < (f y - f a) / (y - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β·
convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β·
Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case h.e'_3 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya✝ : y β‰  a hxy : x < y hxa : x < a hya : y < a ⊒ (f x - f a) / (x - a) = (f a - f x) / (a - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;>
rw [← neg_div_neg_eq]
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;>
Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case h.e'_4 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya✝ : y β‰  a hxy : x < y hxa : x < a hya : y < a ⊒ (f y - f a) / (y - a) = (f a - f y) / (a - y)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;>
rw [← neg_div_neg_eq]
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;>
Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case h.e'_3 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya✝ : y β‰  a hxy : x < y hxa : x < a hya : y < a ⊒ -(f x - f a) / -(x - a) = (f a - f x) / (a - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;>
field_simp
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;>
Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case h.e'_4 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya✝ : y β‰  a hxy : x < y hxa : x < a hya : y < a ⊒ -(f y - f a) / -(y - a) = (f a - f y) / (a - y)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;>
field_simp
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;>
Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case inl.inr π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya✝ : y β‰  a hxy : x < y hxa : x < a hya : y > a ⊒ (f x - f a) / (x - a) < (f y - f a) / (y - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β·
convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β·
Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case h.e'_3 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya✝ : y β‰  a hxy : x < y hxa : x < a hya : y > a ⊒ (f x - f a) / (x - a) = (f a - f x) / (a - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
rw [← neg_div_neg_eq]
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1
Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case h.e'_3 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya✝ : y β‰  a hxy : x < y hxa : x < a hya : y > a ⊒ -(f x - f a) / -(x - a) = (f a - f x) / (a - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq];
field_simp
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq];
Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case inr π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya : y β‰  a hxy : x < y hxa : x > a ⊒ (f x - f a) / (x - a) < (f y - f a) / (y - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β·
exact hf.secant_strict_mono_aux2 ha hy hxa hxy
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β·
Mathlib.Analysis.Convex.Slope.316_0.2UqTeSfXEWgn9kZ
theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConcaveOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa : x β‰  a hya : y β‰  a hxy : x < y ⊒ (f y - f a) / (y - a) < (f x - f a) / (x - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by
Mathlib.Analysis.Convex.Slope.328_0.2UqTeSfXEWgn9kZ
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConcaveOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa : x β‰  a hya : y β‰  a hxy : x < y key : ((-f) x - (-f) a) / (x - a) < ((-f) y - (-f) a) / (y - a) ⊒ (f y - f a) / (y - a) < (f x - f a) / (x - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
simp only [Pi.neg_apply] at key
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy
Mathlib.Analysis.Convex.Slope.328_0.2UqTeSfXEWgn9kZ
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConcaveOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa : x β‰  a hya : y β‰  a hxy : x < y key : (-f x - -f a) / (x - a) < (-f y - -f a) / (y - a) ⊒ (f y - f a) / (y - a) < (f x - f a) / (x - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key
rw [← neg_lt_neg_iff]
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key
Mathlib.Analysis.Convex.Slope.328_0.2UqTeSfXEWgn9kZ
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConcaveOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa : x β‰  a hya : y β‰  a hxy : x < y key : (-f x - -f a) / (x - a) < (-f y - -f a) / (y - a) ⊒ -((f x - f a) / (x - a)) < -((f y - f a) / (y - a))
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff]
convert key using 1
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff]
Mathlib.Analysis.Convex.Slope.328_0.2UqTeSfXEWgn9kZ
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a)
Mathlib_Analysis_Convex_Slope
case h.e'_3 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConcaveOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa : x β‰  a hya : y β‰  a hxy : x < y key : (-f x - -f a) / (x - a) < (-f y - -f a) / (y - a) ⊒ -((f x - f a) / (x - a)) = (-f x - -f a) / (x - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;>
field_simp
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;>
Mathlib.Analysis.Convex.Slope.328_0.2UqTeSfXEWgn9kZ
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a)
Mathlib_Analysis_Convex_Slope
case h.e'_4 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConcaveOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa : x β‰  a hya : y β‰  a hxy : x < y key : (-f x - -f a) / (x - a) < (-f y - -f a) / (y - a) ⊒ -((f y - f a) / (y - a)) = (-f y - -f a) / (y - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;>
field_simp
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;>
Mathlib.Analysis.Convex.Slope.328_0.2UqTeSfXEWgn9kZ
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a)
Mathlib_Analysis_Convex_Slope
case h.e'_3 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConcaveOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa : x β‰  a hya : y β‰  a hxy : x < y key : (-f x - -f a) / (x - a) < (-f y - -f a) / (y - a) ⊒ (f a - f x) / (x - a) = (-f x + f a) / (x - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;>
ring
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;>
Mathlib.Analysis.Convex.Slope.328_0.2UqTeSfXEWgn9kZ
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a)
Mathlib_Analysis_Convex_Slope
case h.e'_4 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConcaveOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa : x β‰  a hya : y β‰  a hxy : x < y key : (-f x - -f a) / (x - a) < (-f y - -f a) / (y - a) ⊒ (f a - f y) / (y - a) = (-f y + f a) / (y - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;>
ring
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;>
Mathlib.Analysis.Convex.Slope.328_0.2UqTeSfXEWgn9kZ
theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y : π•œ hx : x ∈ s hxy : x < y hxy' : f x < f y ⊒ StrictMonoOn f (s ∩ Set.Ici y)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;> ring #align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by
intro u hu v hv huv
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by
Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y : π•œ hx : x ∈ s hxy : x < y hxy' : f x < f y u : π•œ hu : u ∈ s ∩ Set.Ici y v : π•œ hv : v ∈ s ∩ Set.Ici y huv : u < v ⊒ f u < f v
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;> ring #align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv
have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv
Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y : π•œ hx : x ∈ s hxy : x < y hxy' : f x < f y u : π•œ hu : u ∈ s ∩ Set.Ici y v : π•œ hv : v ∈ s ∩ Set.Ici y huv : u < v ⊒ βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;> ring #align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by
intros z hz
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by
Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y : π•œ hx : x ∈ s hxy : x < y hxy' : f x < f y u : π•œ hu : u ∈ s ∩ Set.Ici y v : π•œ hv : v ∈ s ∩ Set.Ici y huv : u < v z : π•œ hz : z ∈ s ∩ Set.Ioi y ⊒ f y < f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;> ring #align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz
refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz
Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y : π•œ hx : x ∈ s hxy : x < y hxy' : f x < f y u : π•œ hu : u ∈ s ∩ Set.Ici y v : π•œ hv : v ∈ s ∩ Set.Ici y huv : u < v z : π•œ hz : z ∈ s ∩ Set.Ioi y ⊒ y ∈ openSegment π•œ x z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;> ring #align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
rw [openSegment_eq_Ioo (hxy.trans hz.2)]
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy'
Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y : π•œ hx : x ∈ s hxy : x < y hxy' : f x < f y u : π•œ hu : u ∈ s ∩ Set.Ici y v : π•œ hv : v ∈ s ∩ Set.Ici y huv : u < v z : π•œ hz : z ∈ s ∩ Set.Ioi y ⊒ y ∈ Set.Ioo x z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;> ring #align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)]
exact ⟨hxy, hz.2⟩
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)]
Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y : π•œ hx : x ∈ s hxy : x < y hxy' : f x < f y u : π•œ hu : u ∈ s ∩ Set.Ici y v : π•œ hv : v ∈ s ∩ Set.Ici y huv : u < v step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z ⊒ f u < f v
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;> ring #align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩
rcases eq_or_lt_of_le hu.2 with (rfl | hu2)
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩
Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y)
Mathlib_Analysis_Convex_Slope
case inl π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y : π•œ hx : x ∈ s hxy : x < y hxy' : f x < f y v : π•œ hv : v ∈ s ∩ Set.Ici y step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z hu : y ∈ s ∩ Set.Ici y huv : y < v ⊒ f y < f v
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;> ring #align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩ rcases eq_or_lt_of_le hu.2 with (rfl | hu2) Β·
exact step1 ⟨hv.1, huv⟩
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩ rcases eq_or_lt_of_le hu.2 with (rfl | hu2) Β·
Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y)
Mathlib_Analysis_Convex_Slope
case inr π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y : π•œ hx : x ∈ s hxy : x < y hxy' : f x < f y u : π•œ hu : u ∈ s ∩ Set.Ici y v : π•œ hv : v ∈ s ∩ Set.Ici y huv : u < v step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z hu2 : y < u ⊒ f u < f v
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;> ring #align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩ rcases eq_or_lt_of_le hu.2 with (rfl | hu2) Β· exact step1 ⟨hv.1, huv⟩ Β·
refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 ⟨hu.1, hu2⟩)
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩ rcases eq_or_lt_of_le hu.2 with (rfl | hu2) Β· exact step1 ⟨hv.1, huv⟩ Β·
Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y)
Mathlib_Analysis_Convex_Slope
case inr.refine'_1 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y : π•œ hx : x ∈ s hxy : x < y hxy' : f x < f y u : π•œ hu : u ∈ s ∩ Set.Ici y v : π•œ hv : v ∈ s ∩ Set.Ici y huv : u < v step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z hu2 : y < u ⊒ y ∈ s
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;> ring #align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩ rcases eq_or_lt_of_le hu.2 with (rfl | hu2) Β· exact step1 ⟨hv.1, huv⟩ Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 ⟨hu.1, hu2⟩) Β·
apply hf.1.segment_subset hx hu.1
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩ rcases eq_or_lt_of_le hu.2 with (rfl | hu2) Β· exact step1 ⟨hv.1, huv⟩ Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 ⟨hu.1, hu2⟩) Β·
Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y)
Mathlib_Analysis_Convex_Slope
case inr.refine'_1.a π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y : π•œ hx : x ∈ s hxy : x < y hxy' : f x < f y u : π•œ hu : u ∈ s ∩ Set.Ici y v : π•œ hv : v ∈ s ∩ Set.Ici y huv : u < v step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z hu2 : y < u ⊒ y ∈ segment π•œ x u
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;> ring #align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩ rcases eq_or_lt_of_le hu.2 with (rfl | hu2) Β· exact step1 ⟨hv.1, huv⟩ Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 ⟨hu.1, hu2⟩) Β· apply hf.1.segment_subset hx hu.1
rw [segment_eq_Icc (hxy.le.trans hu.2)]
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩ rcases eq_or_lt_of_le hu.2 with (rfl | hu2) Β· exact step1 ⟨hv.1, huv⟩ Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 ⟨hu.1, hu2⟩) Β· apply hf.1.segment_subset hx hu.1
Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y)
Mathlib_Analysis_Convex_Slope
case inr.refine'_1.a π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y : π•œ hx : x ∈ s hxy : x < y hxy' : f x < f y u : π•œ hu : u ∈ s ∩ Set.Ici y v : π•œ hv : v ∈ s ∩ Set.Ici y huv : u < v step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z hu2 : y < u ⊒ y ∈ Set.Icc x u
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;> ring #align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩ rcases eq_or_lt_of_le hu.2 with (rfl | hu2) Β· exact step1 ⟨hv.1, huv⟩ Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 ⟨hu.1, hu2⟩) Β· apply hf.1.segment_subset hx hu.1 rw [segment_eq_Icc (hxy.le.trans hu.2)]
exact ⟨hxy.le, hu.2⟩
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩ rcases eq_or_lt_of_le hu.2 with (rfl | hu2) Β· exact step1 ⟨hv.1, huv⟩ Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 ⟨hu.1, hu2⟩) Β· apply hf.1.segment_subset hx hu.1 rw [segment_eq_Icc (hxy.le.trans hu.2)]
Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y)
Mathlib_Analysis_Convex_Slope
case inr.refine'_2 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y : π•œ hx : x ∈ s hxy : x < y hxy' : f x < f y u : π•œ hu : u ∈ s ∩ Set.Ici y v : π•œ hv : v ∈ s ∩ Set.Ici y huv : u < v step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z hu2 : y < u ⊒ u ∈ openSegment π•œ y v
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;> ring #align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩ rcases eq_or_lt_of_le hu.2 with (rfl | hu2) Β· exact step1 ⟨hv.1, huv⟩ Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 ⟨hu.1, hu2⟩) Β· apply hf.1.segment_subset hx hu.1 rw [segment_eq_Icc (hxy.le.trans hu.2)] exact ⟨hxy.le, hu.2⟩ Β·
rw [openSegment_eq_Ioo (hu2.trans huv)]
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩ rcases eq_or_lt_of_le hu.2 with (rfl | hu2) Β· exact step1 ⟨hv.1, huv⟩ Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 ⟨hu.1, hu2⟩) Β· apply hf.1.segment_subset hx hu.1 rw [segment_eq_Icc (hxy.le.trans hu.2)] exact ⟨hxy.le, hu.2⟩ Β·
Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y)
Mathlib_Analysis_Convex_Slope
case inr.refine'_2 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y : π•œ hx : x ∈ s hxy : x < y hxy' : f x < f y u : π•œ hu : u ∈ s ∩ Set.Ici y v : π•œ hv : v ∈ s ∩ Set.Ici y huv : u < v step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z hu2 : y < u ⊒ u ∈ Set.Ioo y v
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_mono_aux2 ha hy hxa hxy #align convex_on.secant_mono ConvexOn.secant_mono theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := (hf.2 hx hz (by linarith) ha hb ?_) _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align strict_convex_on.secant_strict_mono_aux1 StrictConvexOn.secant_strict_mono_aux1 theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux2 StrictConvexOn.secant_strict_mono_aux2 theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] #align strict_convex_on.secant_strict_mono_aux3 StrictConvexOn.secant_strict_mono_aux3 theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp Β· exact hf.secant_strict_mono_aux2 ha hy hxa hxy #align strict_convex_on.secant_strict_mono StrictConvexOn.secant_strict_mono theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;> ring #align strict_concave_on.secant_strict_mono StrictConcaveOn.secant_strict_mono /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩ rcases eq_or_lt_of_le hu.2 with (rfl | hu2) Β· exact step1 ⟨hv.1, huv⟩ Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 ⟨hu.1, hu2⟩) Β· apply hf.1.segment_subset hx hu.1 rw [segment_eq_Icc (hxy.le.trans hu.2)] exact ⟨hxy.le, hu.2⟩ Β· rw [openSegment_eq_Ioo (hu2.trans huv)]
exact ⟨hu2, huv⟩
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : βˆ€ {z : π•œ}, z ∈ s ∩ Set.Ioi y β†’ f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩ rcases eq_or_lt_of_le hu.2 with (rfl | hu2) Β· exact step1 ⟨hv.1, huv⟩ Β· refine' hf.lt_right_of_left_lt _ hv.1 _ (step1 ⟨hu.1, hu2⟩) Β· apply hf.1.segment_subset hx hu.1 rw [segment_eq_Icc (hxy.le.trans hu.2)] exact ⟨hxy.le, hu.2⟩ Β· rw [openSegment_eq_Ioo (hu2.trans huv)]
Mathlib.Analysis.Convex.Slope.337_0.2UqTeSfXEWgn9kZ
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y)
Mathlib_Analysis_Convex_Slope
α : Type u_1 β : Type u_2 γ : Type u_3 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β inst✝ : TopologicalSpace γ s t : Compacts α h : s.carrier = t.carrier ⊒ s = t
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by
cases s
instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by
Mathlib.Topology.Sets.Compacts.43_0.XVs1udLPbHOIEoW
instance : SetLike (Compacts Ξ±) Ξ± where coe
Mathlib_Topology_Sets_Compacts
case mk α : Type u_1 β : Type u_2 γ : Type u_3 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β inst✝ : TopologicalSpace γ t : Compacts α carrier✝ : Set α isCompact'✝ : IsCompact carrier✝ h : { carrier := carrier✝, isCompact' := isCompact'✝ }.carrier = t.carrier ⊒ { carrier := carrier✝, isCompact' := isCompact'✝ } = t
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s;
cases t
instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s;
Mathlib.Topology.Sets.Compacts.43_0.XVs1udLPbHOIEoW
instance : SetLike (Compacts Ξ±) Ξ± where coe
Mathlib_Topology_Sets_Compacts
case mk.mk α : Type u_1 β : Type u_2 γ : Type u_3 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β inst✝ : TopologicalSpace γ carrier✝¹ : Set α isCompact'✝¹ : IsCompact carrier✝¹ carrier✝ : Set α isCompact'✝ : IsCompact carrier✝ h : { carrier := carrier✝¹, isCompact' := isCompact'✝¹ }.carrier = { carrier := carrier✝, isCompact' := isCompact'✝ }.carrier ⊒ { carrier := carrier✝¹, isCompact' := isCompact'✝¹ } = { carrier := carrier✝, isCompact' := isCompact'✝ }
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t;
congr
instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t;
Mathlib.Topology.Sets.Compacts.43_0.XVs1udLPbHOIEoW
instance : SetLike (Compacts Ξ±) Ξ± where coe
Mathlib_Topology_Sets_Compacts
Ξ± : Type u_1 Ξ² : Type u_2 Ξ³ : Type u_3 inst✝² : TopologicalSpace Ξ± inst✝¹ : TopologicalSpace Ξ² inst✝ : TopologicalSpace Ξ³ ΞΉ : Type u_4 s : Finset ΞΉ f : ΞΉ β†’ Compacts Ξ± ⊒ ↑(Finset.sup s f) = Finset.sup s fun i => ↑(f i)
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by
refine Finset.cons_induction_on s rfl fun a s _ h => ?_
@[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by
Mathlib.Topology.Sets.Compacts.123_0.XVs1udLPbHOIEoW
@[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i)
Mathlib_Topology_Sets_Compacts
Ξ± : Type u_1 Ξ² : Type u_2 Ξ³ : Type u_3 inst✝² : TopologicalSpace Ξ± inst✝¹ : TopologicalSpace Ξ² inst✝ : TopologicalSpace Ξ³ ΞΉ : Type u_4 s✝ : Finset ΞΉ f : ΞΉ β†’ Compacts Ξ± a : ΞΉ s : Finset ΞΉ x✝ : a βˆ‰ s h : ↑(Finset.sup s f) = Finset.sup s fun i => ↑(f i) ⊒ ↑(Finset.sup (Finset.cons a s x✝) f) = Finset.sup (Finset.cons a s x✝) fun i => ↑(f i)
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_
simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
@[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_
Mathlib.Topology.Sets.Compacts.123_0.XVs1udLPbHOIEoW
@[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i)
Mathlib_Topology_Sets_Compacts
Ξ± : Type u_1 Ξ² : Type u_2 Ξ³ : Type u_3 inst✝² : TopologicalSpace Ξ± inst✝¹ : TopologicalSpace Ξ² inst✝ : TopologicalSpace Ξ³ ΞΉ : Type u_4 s✝ : Finset ΞΉ f : ΞΉ β†’ Compacts Ξ± a : ΞΉ s : Finset ΞΉ x✝ : a βˆ‰ s h : ↑(Finset.sup s f) = Finset.sup s fun i => ↑(f i) ⊒ ↑(f a) βˆͺ ↑(Finset.sup s f) = ↑(f a) βˆͺ Finset.sup s fun i => ↑(f i)
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
congr
@[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union]
Mathlib.Topology.Sets.Compacts.123_0.XVs1udLPbHOIEoW
@[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i)
Mathlib_Topology_Sets_Compacts
Ξ± : Type u_1 Ξ² : Type u_2 Ξ³ : Type u_3 inst✝² : TopologicalSpace Ξ± inst✝¹ : TopologicalSpace Ξ² inst✝ : TopologicalSpace Ξ³ f : Ξ± β‰ƒβ‚œ Ξ² s : Compacts Ξ± ⊒ Compacts.map ⇑(Homeomorph.symm f) (_ : Continuous ⇑(Homeomorph.symm f)) (Compacts.map ⇑f (_ : Continuous ⇑f) s) = s
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by
ext1
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by
Mathlib.Topology.Sets.Compacts.151_0.XVs1udLPbHOIEoW
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun
Mathlib_Topology_Sets_Compacts
case h Ξ± : Type u_1 Ξ² : Type u_2 Ξ³ : Type u_3 inst✝² : TopologicalSpace Ξ± inst✝¹ : TopologicalSpace Ξ² inst✝ : TopologicalSpace Ξ³ f : Ξ± β‰ƒβ‚œ Ξ² s : Compacts Ξ± ⊒ ↑(Compacts.map ⇑(Homeomorph.symm f) (_ : Continuous ⇑(Homeomorph.symm f)) (Compacts.map ⇑f (_ : Continuous ⇑f) s)) = ↑s
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1
simp only [coe_map, ← image_comp, f.symm_comp_self, image_id]
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1
Mathlib.Topology.Sets.Compacts.151_0.XVs1udLPbHOIEoW
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun
Mathlib_Topology_Sets_Compacts
Ξ± : Type u_1 Ξ² : Type u_2 Ξ³ : Type u_3 inst✝² : TopologicalSpace Ξ± inst✝¹ : TopologicalSpace Ξ² inst✝ : TopologicalSpace Ξ³ f : Ξ± β‰ƒβ‚œ Ξ² s : Compacts Ξ² ⊒ Compacts.map ⇑f (_ : Continuous ⇑f) (Compacts.map ⇑(Homeomorph.symm f) (_ : Continuous ⇑(Homeomorph.symm f)) s) = s
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by
ext1
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by
Mathlib.Topology.Sets.Compacts.151_0.XVs1udLPbHOIEoW
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun
Mathlib_Topology_Sets_Compacts
case h Ξ± : Type u_1 Ξ² : Type u_2 Ξ³ : Type u_3 inst✝² : TopologicalSpace Ξ± inst✝¹ : TopologicalSpace Ξ² inst✝ : TopologicalSpace Ξ³ f : Ξ± β‰ƒβ‚œ Ξ² s : Compacts Ξ² ⊒ ↑(Compacts.map ⇑f (_ : Continuous ⇑f) (Compacts.map ⇑(Homeomorph.symm f) (_ : Continuous ⇑(Homeomorph.symm f)) s)) = ↑s
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by ext1
simp only [coe_map, ← image_comp, f.self_comp_symm, image_id]
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by ext1
Mathlib.Topology.Sets.Compacts.151_0.XVs1udLPbHOIEoW
/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun
Mathlib_Topology_Sets_Compacts
α : Type u_1 β : Type u_2 γ : Type u_3 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β inst✝ : TopologicalSpace γ s t : NonemptyCompacts α h : (fun s => s.carrier) s = (fun s => s.carrier) t ⊒ s = t
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by ext1 simp only [coe_map, ← image_comp, f.self_comp_symm, image_id] #align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv @[simp] theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ := Equiv.ext map_id #align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl @[simp] theorem equiv_trans (f : Ξ± β‰ƒβ‚œ Ξ²) (g : Ξ² β‰ƒβ‚œ Ξ³) : Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) := -- porting note: can no longer write `map_comp _ _ _ _` and unify Equiv.ext <| map_comp g f g.continuous f.continuous #align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans @[simp] theorem equiv_symm (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm := rfl #align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm /-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/ theorem coe_equiv_apply_eq_preimage (f : Ξ± β‰ƒβ‚œ Ξ²) (K : Compacts Ξ±) : (Compacts.equiv f K : Set Ξ²) = f.symm ⁻¹' (K : Set Ξ±) := f.toEquiv.image_eq_preimage K #align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage /-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product space. -/ protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ— Ξ²) where carrier := K Γ—Λ’ L isCompact' := IsCompact.prod K.2 L.2 #align topological_space.compacts.prod TopologicalSpace.Compacts.prod @[simp] theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod -- todo: add `pi` end Compacts /-! ### Nonempty compact sets -/ /-- The type of nonempty compact sets of a topological space. -/ structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where nonempty' : carrier.Nonempty #align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts namespace NonemptyCompacts instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by
obtain ⟨⟨_, _⟩, _⟩ := s
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by
Mathlib.Topology.Sets.Compacts.213_0.XVs1udLPbHOIEoW
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s
Mathlib_Topology_Sets_Compacts
case mk.mk α : Type u_1 β : Type u_2 γ : Type u_3 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β inst✝ : TopologicalSpace γ t : NonemptyCompacts α carrier✝ : Set α isCompact'✝ : IsCompact carrier✝ nonempty'✝ : Set.Nonempty { carrier := carrier✝, isCompact' := isCompact'✝ }.carrier h : (fun s => s.carrier) { toCompacts := { carrier := carrier✝, isCompact' := isCompact'✝ }, nonempty' := nonempty'✝ } = (fun s => s.carrier) t ⊒ { toCompacts := { carrier := carrier✝, isCompact' := isCompact'✝ }, nonempty' := nonempty'✝ } = t
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by ext1 simp only [coe_map, ← image_comp, f.self_comp_symm, image_id] #align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv @[simp] theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ := Equiv.ext map_id #align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl @[simp] theorem equiv_trans (f : Ξ± β‰ƒβ‚œ Ξ²) (g : Ξ² β‰ƒβ‚œ Ξ³) : Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) := -- porting note: can no longer write `map_comp _ _ _ _` and unify Equiv.ext <| map_comp g f g.continuous f.continuous #align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans @[simp] theorem equiv_symm (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm := rfl #align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm /-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/ theorem coe_equiv_apply_eq_preimage (f : Ξ± β‰ƒβ‚œ Ξ²) (K : Compacts Ξ±) : (Compacts.equiv f K : Set Ξ²) = f.symm ⁻¹' (K : Set Ξ±) := f.toEquiv.image_eq_preimage K #align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage /-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product space. -/ protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ— Ξ²) where carrier := K Γ—Λ’ L isCompact' := IsCompact.prod K.2 L.2 #align topological_space.compacts.prod TopologicalSpace.Compacts.prod @[simp] theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod -- todo: add `pi` end Compacts /-! ### Nonempty compact sets -/ /-- The type of nonempty compact sets of a topological space. -/ structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where nonempty' : carrier.Nonempty #align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts namespace NonemptyCompacts instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s
obtain ⟨⟨_, _⟩, _⟩ := t
instance : SetLike (NonemptyCompacts α) α where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s
Mathlib.Topology.Sets.Compacts.213_0.XVs1udLPbHOIEoW
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s
Mathlib_Topology_Sets_Compacts
case mk.mk.mk.mk α : Type u_1 β : Type u_2 γ : Type u_3 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β inst✝ : TopologicalSpace γ carrier✝¹ : Set α isCompact'✝¹ : IsCompact carrier✝¹ nonempty'✝¹ : Set.Nonempty { carrier := carrier✝¹, isCompact' := isCompact'✝¹ }.carrier carrier✝ : Set α isCompact'✝ : IsCompact carrier✝ nonempty'✝ : Set.Nonempty { carrier := carrier✝, isCompact' := isCompact'✝ }.carrier h : (fun s => s.carrier) { toCompacts := { carrier := carrier✝¹, isCompact' := isCompact'✝¹ }, nonempty' := nonempty'✝¹ } = (fun s => s.carrier) { toCompacts := { carrier := carrier✝, isCompact' := isCompact'✝ }, nonempty' := nonempty'✝ } ⊒ { toCompacts := { carrier := carrier✝¹, isCompact' := isCompact'✝¹ }, nonempty' := nonempty'✝¹ } = { toCompacts := { carrier := carrier✝, isCompact' := isCompact'✝ }, nonempty' := nonempty'✝ }
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by ext1 simp only [coe_map, ← image_comp, f.self_comp_symm, image_id] #align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv @[simp] theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ := Equiv.ext map_id #align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl @[simp] theorem equiv_trans (f : Ξ± β‰ƒβ‚œ Ξ²) (g : Ξ² β‰ƒβ‚œ Ξ³) : Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) := -- porting note: can no longer write `map_comp _ _ _ _` and unify Equiv.ext <| map_comp g f g.continuous f.continuous #align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans @[simp] theorem equiv_symm (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm := rfl #align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm /-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/ theorem coe_equiv_apply_eq_preimage (f : Ξ± β‰ƒβ‚œ Ξ²) (K : Compacts Ξ±) : (Compacts.equiv f K : Set Ξ²) = f.symm ⁻¹' (K : Set Ξ±) := f.toEquiv.image_eq_preimage K #align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage /-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product space. -/ protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ— Ξ²) where carrier := K Γ—Λ’ L isCompact' := IsCompact.prod K.2 L.2 #align topological_space.compacts.prod TopologicalSpace.Compacts.prod @[simp] theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod -- todo: add `pi` end Compacts /-! ### Nonempty compact sets -/ /-- The type of nonempty compact sets of a topological space. -/ structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where nonempty' : carrier.Nonempty #align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts namespace NonemptyCompacts instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t
congr
instance : SetLike (NonemptyCompacts α) α where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t
Mathlib.Topology.Sets.Compacts.213_0.XVs1udLPbHOIEoW
instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s
Mathlib_Topology_Sets_Compacts
α : Type u_1 β : Type u_2 γ : Type u_3 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β inst✝ : TopologicalSpace γ s t : PositiveCompacts α h : (fun s => s.carrier) s = (fun s => s.carrier) t ⊒ s = t
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by ext1 simp only [coe_map, ← image_comp, f.self_comp_symm, image_id] #align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv @[simp] theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ := Equiv.ext map_id #align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl @[simp] theorem equiv_trans (f : Ξ± β‰ƒβ‚œ Ξ²) (g : Ξ² β‰ƒβ‚œ Ξ³) : Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) := -- porting note: can no longer write `map_comp _ _ _ _` and unify Equiv.ext <| map_comp g f g.continuous f.continuous #align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans @[simp] theorem equiv_symm (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm := rfl #align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm /-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/ theorem coe_equiv_apply_eq_preimage (f : Ξ± β‰ƒβ‚œ Ξ²) (K : Compacts Ξ±) : (Compacts.equiv f K : Set Ξ²) = f.symm ⁻¹' (K : Set Ξ±) := f.toEquiv.image_eq_preimage K #align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage /-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product space. -/ protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ— Ξ²) where carrier := K Γ—Λ’ L isCompact' := IsCompact.prod K.2 L.2 #align topological_space.compacts.prod TopologicalSpace.Compacts.prod @[simp] theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod -- todo: add `pi` end Compacts /-! ### Nonempty compact sets -/ /-- The type of nonempty compact sets of a topological space. -/ structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where nonempty' : carrier.Nonempty #align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts namespace NonemptyCompacts instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s initialize_simps_projections NonemptyCompacts (carrier β†’ coe) protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.nonempty' #align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty /-- Reinterpret a nonempty compact as a closed set. -/ def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± := ⟨s, s.isCompact.isClosed⟩ #align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds @[ext] protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk -- porting note: `@[simp]` moved to `coe_toCompacts` theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s := rfl #align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe @[simp] -- porting note: new lemma theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (NonemptyCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.nonempty.mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) := ⟨⟨⊀, univ_nonempty⟩⟩ instance : SemilatticeSup (NonemptyCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : NonemptyCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : NonemptyCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top /-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with default element the singleton set containing the default element. -/ instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) := ⟨{ carrier := {default} isCompact' := isCompact_singleton nonempty' := singleton_nonempty _ }⟩ instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s := isCompact_iff_compactSpace.1 s.isCompact #align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s := s.nonempty.to_subtype #align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty /-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts` in the product space. -/ protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ— Ξ²) := { K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty } #align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod @[simp] theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod end NonemptyCompacts /-! ### Positive compact sets -/ /-- The type of compact sets with nonempty interior of a topological space. See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/ structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where interior_nonempty' : (interior carrier).Nonempty #align topological_space.positive_compacts TopologicalSpace.PositiveCompacts namespace PositiveCompacts instance : SetLike (PositiveCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by
obtain ⟨⟨_, _⟩, _⟩ := s
instance : SetLike (PositiveCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by
Mathlib.Topology.Sets.Compacts.317_0.XVs1udLPbHOIEoW
instance : SetLike (PositiveCompacts Ξ±) Ξ± where coe s
Mathlib_Topology_Sets_Compacts
case mk.mk α : Type u_1 β : Type u_2 γ : Type u_3 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β inst✝ : TopologicalSpace γ t : PositiveCompacts α carrier✝ : Set α isCompact'✝ : IsCompact carrier✝ interior_nonempty'✝ : Set.Nonempty (interior { carrier := carrier✝, isCompact' := isCompact'✝ }.carrier) h : (fun s => s.carrier) { toCompacts := { carrier := carrier✝, isCompact' := isCompact'✝ }, interior_nonempty' := interior_nonempty'✝ } = (fun s => s.carrier) t ⊒ { toCompacts := { carrier := carrier✝, isCompact' := isCompact'✝ }, interior_nonempty' := interior_nonempty'✝ } = t
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by ext1 simp only [coe_map, ← image_comp, f.self_comp_symm, image_id] #align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv @[simp] theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ := Equiv.ext map_id #align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl @[simp] theorem equiv_trans (f : Ξ± β‰ƒβ‚œ Ξ²) (g : Ξ² β‰ƒβ‚œ Ξ³) : Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) := -- porting note: can no longer write `map_comp _ _ _ _` and unify Equiv.ext <| map_comp g f g.continuous f.continuous #align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans @[simp] theorem equiv_symm (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm := rfl #align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm /-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/ theorem coe_equiv_apply_eq_preimage (f : Ξ± β‰ƒβ‚œ Ξ²) (K : Compacts Ξ±) : (Compacts.equiv f K : Set Ξ²) = f.symm ⁻¹' (K : Set Ξ±) := f.toEquiv.image_eq_preimage K #align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage /-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product space. -/ protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ— Ξ²) where carrier := K Γ—Λ’ L isCompact' := IsCompact.prod K.2 L.2 #align topological_space.compacts.prod TopologicalSpace.Compacts.prod @[simp] theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod -- todo: add `pi` end Compacts /-! ### Nonempty compact sets -/ /-- The type of nonempty compact sets of a topological space. -/ structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where nonempty' : carrier.Nonempty #align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts namespace NonemptyCompacts instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s initialize_simps_projections NonemptyCompacts (carrier β†’ coe) protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.nonempty' #align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty /-- Reinterpret a nonempty compact as a closed set. -/ def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± := ⟨s, s.isCompact.isClosed⟩ #align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds @[ext] protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk -- porting note: `@[simp]` moved to `coe_toCompacts` theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s := rfl #align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe @[simp] -- porting note: new lemma theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (NonemptyCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.nonempty.mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) := ⟨⟨⊀, univ_nonempty⟩⟩ instance : SemilatticeSup (NonemptyCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : NonemptyCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : NonemptyCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top /-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with default element the singleton set containing the default element. -/ instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) := ⟨{ carrier := {default} isCompact' := isCompact_singleton nonempty' := singleton_nonempty _ }⟩ instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s := isCompact_iff_compactSpace.1 s.isCompact #align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s := s.nonempty.to_subtype #align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty /-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts` in the product space. -/ protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ— Ξ²) := { K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty } #align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod @[simp] theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod end NonemptyCompacts /-! ### Positive compact sets -/ /-- The type of compact sets with nonempty interior of a topological space. See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/ structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where interior_nonempty' : (interior carrier).Nonempty #align topological_space.positive_compacts TopologicalSpace.PositiveCompacts namespace PositiveCompacts instance : SetLike (PositiveCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s
obtain ⟨⟨_, _⟩, _⟩ := t
instance : SetLike (PositiveCompacts α) α where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s
Mathlib.Topology.Sets.Compacts.317_0.XVs1udLPbHOIEoW
instance : SetLike (PositiveCompacts Ξ±) Ξ± where coe s
Mathlib_Topology_Sets_Compacts
case mk.mk.mk.mk α : Type u_1 β : Type u_2 γ : Type u_3 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β inst✝ : TopologicalSpace γ carrier✝¹ : Set α isCompact'✝¹ : IsCompact carrier✝¹ interior_nonempty'✝¹ : Set.Nonempty (interior { carrier := carrier✝¹, isCompact' := isCompact'✝¹ }.carrier) carrier✝ : Set α isCompact'✝ : IsCompact carrier✝ interior_nonempty'✝ : Set.Nonempty (interior { carrier := carrier✝, isCompact' := isCompact'✝ }.carrier) h : (fun s => s.carrier) { toCompacts := { carrier := carrier✝¹, isCompact' := isCompact'✝¹ }, interior_nonempty' := interior_nonempty'✝¹ } = (fun s => s.carrier) { toCompacts := { carrier := carrier✝, isCompact' := isCompact'✝ }, interior_nonempty' := interior_nonempty'✝ } ⊒ { toCompacts := { carrier := carrier✝¹, isCompact' := isCompact'✝¹ }, interior_nonempty' := interior_nonempty'✝¹ } = { toCompacts := { carrier := carrier✝, isCompact' := isCompact'✝ }, interior_nonempty' := interior_nonempty'✝ }
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by ext1 simp only [coe_map, ← image_comp, f.self_comp_symm, image_id] #align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv @[simp] theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ := Equiv.ext map_id #align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl @[simp] theorem equiv_trans (f : Ξ± β‰ƒβ‚œ Ξ²) (g : Ξ² β‰ƒβ‚œ Ξ³) : Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) := -- porting note: can no longer write `map_comp _ _ _ _` and unify Equiv.ext <| map_comp g f g.continuous f.continuous #align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans @[simp] theorem equiv_symm (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm := rfl #align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm /-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/ theorem coe_equiv_apply_eq_preimage (f : Ξ± β‰ƒβ‚œ Ξ²) (K : Compacts Ξ±) : (Compacts.equiv f K : Set Ξ²) = f.symm ⁻¹' (K : Set Ξ±) := f.toEquiv.image_eq_preimage K #align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage /-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product space. -/ protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ— Ξ²) where carrier := K Γ—Λ’ L isCompact' := IsCompact.prod K.2 L.2 #align topological_space.compacts.prod TopologicalSpace.Compacts.prod @[simp] theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod -- todo: add `pi` end Compacts /-! ### Nonempty compact sets -/ /-- The type of nonempty compact sets of a topological space. -/ structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where nonempty' : carrier.Nonempty #align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts namespace NonemptyCompacts instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s initialize_simps_projections NonemptyCompacts (carrier β†’ coe) protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.nonempty' #align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty /-- Reinterpret a nonempty compact as a closed set. -/ def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± := ⟨s, s.isCompact.isClosed⟩ #align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds @[ext] protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk -- porting note: `@[simp]` moved to `coe_toCompacts` theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s := rfl #align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe @[simp] -- porting note: new lemma theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (NonemptyCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.nonempty.mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) := ⟨⟨⊀, univ_nonempty⟩⟩ instance : SemilatticeSup (NonemptyCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : NonemptyCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : NonemptyCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top /-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with default element the singleton set containing the default element. -/ instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) := ⟨{ carrier := {default} isCompact' := isCompact_singleton nonempty' := singleton_nonempty _ }⟩ instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s := isCompact_iff_compactSpace.1 s.isCompact #align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s := s.nonempty.to_subtype #align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty /-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts` in the product space. -/ protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ— Ξ²) := { K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty } #align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod @[simp] theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod end NonemptyCompacts /-! ### Positive compact sets -/ /-- The type of compact sets with nonempty interior of a topological space. See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/ structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where interior_nonempty' : (interior carrier).Nonempty #align topological_space.positive_compacts TopologicalSpace.PositiveCompacts namespace PositiveCompacts instance : SetLike (PositiveCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t
congr
instance : SetLike (PositiveCompacts α) α where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t
Mathlib.Topology.Sets.Compacts.317_0.XVs1udLPbHOIEoW
instance : SetLike (PositiveCompacts Ξ±) Ξ± where coe s
Mathlib_Topology_Sets_Compacts
α : Type u_1 β : Type u_2 γ : Type u_3 inst✝⁴ : TopologicalSpace α inst✝³ : TopologicalSpace β inst✝² : TopologicalSpace γ inst✝¹ : WeaklyLocallyCompactSpace α inst✝ : Nonempty α ⊒ Nonempty (PositiveCompacts α)
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by ext1 simp only [coe_map, ← image_comp, f.self_comp_symm, image_id] #align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv @[simp] theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ := Equiv.ext map_id #align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl @[simp] theorem equiv_trans (f : Ξ± β‰ƒβ‚œ Ξ²) (g : Ξ² β‰ƒβ‚œ Ξ³) : Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) := -- porting note: can no longer write `map_comp _ _ _ _` and unify Equiv.ext <| map_comp g f g.continuous f.continuous #align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans @[simp] theorem equiv_symm (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm := rfl #align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm /-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/ theorem coe_equiv_apply_eq_preimage (f : Ξ± β‰ƒβ‚œ Ξ²) (K : Compacts Ξ±) : (Compacts.equiv f K : Set Ξ²) = f.symm ⁻¹' (K : Set Ξ±) := f.toEquiv.image_eq_preimage K #align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage /-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product space. -/ protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ— Ξ²) where carrier := K Γ—Λ’ L isCompact' := IsCompact.prod K.2 L.2 #align topological_space.compacts.prod TopologicalSpace.Compacts.prod @[simp] theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod -- todo: add `pi` end Compacts /-! ### Nonempty compact sets -/ /-- The type of nonempty compact sets of a topological space. -/ structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where nonempty' : carrier.Nonempty #align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts namespace NonemptyCompacts instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s initialize_simps_projections NonemptyCompacts (carrier β†’ coe) protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.nonempty' #align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty /-- Reinterpret a nonempty compact as a closed set. -/ def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± := ⟨s, s.isCompact.isClosed⟩ #align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds @[ext] protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk -- porting note: `@[simp]` moved to `coe_toCompacts` theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s := rfl #align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe @[simp] -- porting note: new lemma theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (NonemptyCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.nonempty.mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) := ⟨⟨⊀, univ_nonempty⟩⟩ instance : SemilatticeSup (NonemptyCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : NonemptyCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : NonemptyCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top /-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with default element the singleton set containing the default element. -/ instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) := ⟨{ carrier := {default} isCompact' := isCompact_singleton nonempty' := singleton_nonempty _ }⟩ instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s := isCompact_iff_compactSpace.1 s.isCompact #align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s := s.nonempty.to_subtype #align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty /-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts` in the product space. -/ protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ— Ξ²) := { K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty } #align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod @[simp] theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod end NonemptyCompacts /-! ### Positive compact sets -/ /-- The type of compact sets with nonempty interior of a topological space. See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/ structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where interior_nonempty' : (interior carrier).Nonempty #align topological_space.positive_compacts TopologicalSpace.PositiveCompacts namespace PositiveCompacts instance : SetLike (PositiveCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : PositiveCompacts Ξ±) : Set Ξ± := s initialize_simps_projections PositiveCompacts (carrier β†’ coe) protected theorem isCompact (s : PositiveCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.positive_compacts.is_compact TopologicalSpace.PositiveCompacts.isCompact theorem interior_nonempty (s : PositiveCompacts Ξ±) : (interior (s : Set Ξ±)).Nonempty := s.interior_nonempty' #align topological_space.positive_compacts.interior_nonempty TopologicalSpace.PositiveCompacts.interior_nonempty protected theorem nonempty (s : PositiveCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.interior_nonempty.mono interior_subset #align topological_space.positive_compacts.nonempty TopologicalSpace.PositiveCompacts.nonempty /-- Reinterpret a positive compact as a nonempty compact. -/ def toNonemptyCompacts (s : PositiveCompacts Ξ±) : NonemptyCompacts Ξ± := ⟨s.toCompacts, s.nonempty⟩ #align topological_space.positive_compacts.to_nonempty_compacts TopologicalSpace.PositiveCompacts.toNonemptyCompacts @[ext] protected theorem ext {s t : PositiveCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.positive_compacts.ext TopologicalSpace.PositiveCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.positive_compacts.coe_mk TopologicalSpace.PositiveCompacts.coe_mk -- porting note: `@[simp]` moved to a new lemma theorem carrier_eq_coe (s : PositiveCompacts Ξ±) : s.carrier = s := rfl #align topological_space.positive_compacts.carrier_eq_coe TopologicalSpace.PositiveCompacts.carrier_eq_coe @[simp] theorem coe_toCompacts (s : PositiveCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (PositiveCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.interior_nonempty.mono <| interior_mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (PositiveCompacts Ξ±) := ⟨⟨⊀, interior_univ.symm.subst univ_nonempty⟩⟩ instance : SemilatticeSup (PositiveCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (PositiveCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : PositiveCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : PositiveCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.positive_compacts.coe_top TopologicalSpace.PositiveCompacts.coe_top /-- The image of a positive compact set under a continuous open map. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (hf' : IsOpenMap f) (K : PositiveCompacts Ξ±) : PositiveCompacts Ξ² := { Compacts.map f hf K.toCompacts with interior_nonempty' := (K.interior_nonempty'.image _).mono (hf'.image_interior_subset K.toCompacts) } #align topological_space.positive_compacts.map TopologicalSpace.PositiveCompacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (hf' : IsOpenMap f) (s : PositiveCompacts Ξ±) : (s.map f hf hf' : Set Ξ²) = f '' s := rfl #align topological_space.positive_compacts.coe_map TopologicalSpace.PositiveCompacts.coe_map @[simp] theorem map_id (K : PositiveCompacts Ξ±) : K.map id continuous_id IsOpenMap.id = K := PositiveCompacts.ext <| Set.image_id _ #align topological_space.positive_compacts.map_id TopologicalSpace.PositiveCompacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f) (hg' : IsOpenMap g) (K : PositiveCompacts Ξ±) : K.map (f ∘ g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' := PositiveCompacts.ext <| Set.image_comp _ _ _ #align topological_space.positive_compacts.map_comp TopologicalSpace.PositiveCompacts.map_comp theorem _root_.exists_positiveCompacts_subset [LocallyCompactSpace Ξ±] {U : Set Ξ±} (ho : IsOpen U) (hn : U.Nonempty) : βˆƒ K : PositiveCompacts Ξ±, ↑K βŠ† U := let ⟨x, hx⟩ := hn let ⟨K, hKc, hxK, hKU⟩ := exists_compact_subset ho hx ⟨⟨⟨K, hKc⟩, ⟨x, hxK⟩⟩, hKU⟩ #align exists_positive_compacts_subset exists_positiveCompacts_subset instance [CompactSpace Ξ±] [Nonempty Ξ±] : Inhabited (PositiveCompacts Ξ±) := ⟨⊀⟩ /-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/ instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by
inhabit Ξ±
/-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/ instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by
Mathlib.Topology.Sets.Compacts.424_0.XVs1udLPbHOIEoW
/-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/ instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±)
Mathlib_Topology_Sets_Compacts
α : Type u_1 β : Type u_2 γ : Type u_3 inst✝⁴ : TopologicalSpace α inst✝³ : TopologicalSpace β inst✝² : TopologicalSpace γ inst✝¹ : WeaklyLocallyCompactSpace α inst✝ : Nonempty α inhabited_h : Inhabited α ⊒ Nonempty (PositiveCompacts α)
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by ext1 simp only [coe_map, ← image_comp, f.self_comp_symm, image_id] #align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv @[simp] theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ := Equiv.ext map_id #align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl @[simp] theorem equiv_trans (f : Ξ± β‰ƒβ‚œ Ξ²) (g : Ξ² β‰ƒβ‚œ Ξ³) : Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) := -- porting note: can no longer write `map_comp _ _ _ _` and unify Equiv.ext <| map_comp g f g.continuous f.continuous #align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans @[simp] theorem equiv_symm (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm := rfl #align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm /-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/ theorem coe_equiv_apply_eq_preimage (f : Ξ± β‰ƒβ‚œ Ξ²) (K : Compacts Ξ±) : (Compacts.equiv f K : Set Ξ²) = f.symm ⁻¹' (K : Set Ξ±) := f.toEquiv.image_eq_preimage K #align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage /-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product space. -/ protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ— Ξ²) where carrier := K Γ—Λ’ L isCompact' := IsCompact.prod K.2 L.2 #align topological_space.compacts.prod TopologicalSpace.Compacts.prod @[simp] theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod -- todo: add `pi` end Compacts /-! ### Nonempty compact sets -/ /-- The type of nonempty compact sets of a topological space. -/ structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where nonempty' : carrier.Nonempty #align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts namespace NonemptyCompacts instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s initialize_simps_projections NonemptyCompacts (carrier β†’ coe) protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.nonempty' #align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty /-- Reinterpret a nonempty compact as a closed set. -/ def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± := ⟨s, s.isCompact.isClosed⟩ #align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds @[ext] protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk -- porting note: `@[simp]` moved to `coe_toCompacts` theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s := rfl #align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe @[simp] -- porting note: new lemma theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (NonemptyCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.nonempty.mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) := ⟨⟨⊀, univ_nonempty⟩⟩ instance : SemilatticeSup (NonemptyCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : NonemptyCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : NonemptyCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top /-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with default element the singleton set containing the default element. -/ instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) := ⟨{ carrier := {default} isCompact' := isCompact_singleton nonempty' := singleton_nonempty _ }⟩ instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s := isCompact_iff_compactSpace.1 s.isCompact #align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s := s.nonempty.to_subtype #align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty /-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts` in the product space. -/ protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ— Ξ²) := { K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty } #align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod @[simp] theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod end NonemptyCompacts /-! ### Positive compact sets -/ /-- The type of compact sets with nonempty interior of a topological space. See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/ structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where interior_nonempty' : (interior carrier).Nonempty #align topological_space.positive_compacts TopologicalSpace.PositiveCompacts namespace PositiveCompacts instance : SetLike (PositiveCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : PositiveCompacts Ξ±) : Set Ξ± := s initialize_simps_projections PositiveCompacts (carrier β†’ coe) protected theorem isCompact (s : PositiveCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.positive_compacts.is_compact TopologicalSpace.PositiveCompacts.isCompact theorem interior_nonempty (s : PositiveCompacts Ξ±) : (interior (s : Set Ξ±)).Nonempty := s.interior_nonempty' #align topological_space.positive_compacts.interior_nonempty TopologicalSpace.PositiveCompacts.interior_nonempty protected theorem nonempty (s : PositiveCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.interior_nonempty.mono interior_subset #align topological_space.positive_compacts.nonempty TopologicalSpace.PositiveCompacts.nonempty /-- Reinterpret a positive compact as a nonempty compact. -/ def toNonemptyCompacts (s : PositiveCompacts Ξ±) : NonemptyCompacts Ξ± := ⟨s.toCompacts, s.nonempty⟩ #align topological_space.positive_compacts.to_nonempty_compacts TopologicalSpace.PositiveCompacts.toNonemptyCompacts @[ext] protected theorem ext {s t : PositiveCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.positive_compacts.ext TopologicalSpace.PositiveCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.positive_compacts.coe_mk TopologicalSpace.PositiveCompacts.coe_mk -- porting note: `@[simp]` moved to a new lemma theorem carrier_eq_coe (s : PositiveCompacts Ξ±) : s.carrier = s := rfl #align topological_space.positive_compacts.carrier_eq_coe TopologicalSpace.PositiveCompacts.carrier_eq_coe @[simp] theorem coe_toCompacts (s : PositiveCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (PositiveCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.interior_nonempty.mono <| interior_mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (PositiveCompacts Ξ±) := ⟨⟨⊀, interior_univ.symm.subst univ_nonempty⟩⟩ instance : SemilatticeSup (PositiveCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (PositiveCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : PositiveCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : PositiveCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.positive_compacts.coe_top TopologicalSpace.PositiveCompacts.coe_top /-- The image of a positive compact set under a continuous open map. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (hf' : IsOpenMap f) (K : PositiveCompacts Ξ±) : PositiveCompacts Ξ² := { Compacts.map f hf K.toCompacts with interior_nonempty' := (K.interior_nonempty'.image _).mono (hf'.image_interior_subset K.toCompacts) } #align topological_space.positive_compacts.map TopologicalSpace.PositiveCompacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (hf' : IsOpenMap f) (s : PositiveCompacts Ξ±) : (s.map f hf hf' : Set Ξ²) = f '' s := rfl #align topological_space.positive_compacts.coe_map TopologicalSpace.PositiveCompacts.coe_map @[simp] theorem map_id (K : PositiveCompacts Ξ±) : K.map id continuous_id IsOpenMap.id = K := PositiveCompacts.ext <| Set.image_id _ #align topological_space.positive_compacts.map_id TopologicalSpace.PositiveCompacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f) (hg' : IsOpenMap g) (K : PositiveCompacts Ξ±) : K.map (f ∘ g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' := PositiveCompacts.ext <| Set.image_comp _ _ _ #align topological_space.positive_compacts.map_comp TopologicalSpace.PositiveCompacts.map_comp theorem _root_.exists_positiveCompacts_subset [LocallyCompactSpace Ξ±] {U : Set Ξ±} (ho : IsOpen U) (hn : U.Nonempty) : βˆƒ K : PositiveCompacts Ξ±, ↑K βŠ† U := let ⟨x, hx⟩ := hn let ⟨K, hKc, hxK, hKU⟩ := exists_compact_subset ho hx ⟨⟨⟨K, hKc⟩, ⟨x, hxK⟩⟩, hKU⟩ #align exists_positive_compacts_subset exists_positiveCompacts_subset instance [CompactSpace Ξ±] [Nonempty Ξ±] : Inhabited (PositiveCompacts Ξ±) := ⟨⊀⟩ /-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/ instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by inhabit Ξ±
rcases exists_compact_mem_nhds (default : α) with ⟨K, hKc, hK⟩
/-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/ instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by inhabit Ξ±
Mathlib.Topology.Sets.Compacts.424_0.XVs1udLPbHOIEoW
/-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/ instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±)
Mathlib_Topology_Sets_Compacts
case intro.intro α : Type u_1 β : Type u_2 γ : Type u_3 inst✝⁴ : TopologicalSpace α inst✝³ : TopologicalSpace β inst✝² : TopologicalSpace γ inst✝¹ : WeaklyLocallyCompactSpace α inst✝ : Nonempty α inhabited_h : Inhabited α K : Set α hKc : IsCompact K hK : K ∈ nhds default ⊒ Nonempty (PositiveCompacts α)
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by ext1 simp only [coe_map, ← image_comp, f.self_comp_symm, image_id] #align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv @[simp] theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ := Equiv.ext map_id #align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl @[simp] theorem equiv_trans (f : Ξ± β‰ƒβ‚œ Ξ²) (g : Ξ² β‰ƒβ‚œ Ξ³) : Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) := -- porting note: can no longer write `map_comp _ _ _ _` and unify Equiv.ext <| map_comp g f g.continuous f.continuous #align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans @[simp] theorem equiv_symm (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm := rfl #align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm /-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/ theorem coe_equiv_apply_eq_preimage (f : Ξ± β‰ƒβ‚œ Ξ²) (K : Compacts Ξ±) : (Compacts.equiv f K : Set Ξ²) = f.symm ⁻¹' (K : Set Ξ±) := f.toEquiv.image_eq_preimage K #align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage /-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product space. -/ protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ— Ξ²) where carrier := K Γ—Λ’ L isCompact' := IsCompact.prod K.2 L.2 #align topological_space.compacts.prod TopologicalSpace.Compacts.prod @[simp] theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod -- todo: add `pi` end Compacts /-! ### Nonempty compact sets -/ /-- The type of nonempty compact sets of a topological space. -/ structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where nonempty' : carrier.Nonempty #align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts namespace NonemptyCompacts instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s initialize_simps_projections NonemptyCompacts (carrier β†’ coe) protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.nonempty' #align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty /-- Reinterpret a nonempty compact as a closed set. -/ def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± := ⟨s, s.isCompact.isClosed⟩ #align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds @[ext] protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk -- porting note: `@[simp]` moved to `coe_toCompacts` theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s := rfl #align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe @[simp] -- porting note: new lemma theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (NonemptyCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.nonempty.mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) := ⟨⟨⊀, univ_nonempty⟩⟩ instance : SemilatticeSup (NonemptyCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : NonemptyCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : NonemptyCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top /-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with default element the singleton set containing the default element. -/ instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) := ⟨{ carrier := {default} isCompact' := isCompact_singleton nonempty' := singleton_nonempty _ }⟩ instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s := isCompact_iff_compactSpace.1 s.isCompact #align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s := s.nonempty.to_subtype #align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty /-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts` in the product space. -/ protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ— Ξ²) := { K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty } #align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod @[simp] theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod end NonemptyCompacts /-! ### Positive compact sets -/ /-- The type of compact sets with nonempty interior of a topological space. See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/ structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where interior_nonempty' : (interior carrier).Nonempty #align topological_space.positive_compacts TopologicalSpace.PositiveCompacts namespace PositiveCompacts instance : SetLike (PositiveCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : PositiveCompacts Ξ±) : Set Ξ± := s initialize_simps_projections PositiveCompacts (carrier β†’ coe) protected theorem isCompact (s : PositiveCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.positive_compacts.is_compact TopologicalSpace.PositiveCompacts.isCompact theorem interior_nonempty (s : PositiveCompacts Ξ±) : (interior (s : Set Ξ±)).Nonempty := s.interior_nonempty' #align topological_space.positive_compacts.interior_nonempty TopologicalSpace.PositiveCompacts.interior_nonempty protected theorem nonempty (s : PositiveCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.interior_nonempty.mono interior_subset #align topological_space.positive_compacts.nonempty TopologicalSpace.PositiveCompacts.nonempty /-- Reinterpret a positive compact as a nonempty compact. -/ def toNonemptyCompacts (s : PositiveCompacts Ξ±) : NonemptyCompacts Ξ± := ⟨s.toCompacts, s.nonempty⟩ #align topological_space.positive_compacts.to_nonempty_compacts TopologicalSpace.PositiveCompacts.toNonemptyCompacts @[ext] protected theorem ext {s t : PositiveCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.positive_compacts.ext TopologicalSpace.PositiveCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.positive_compacts.coe_mk TopologicalSpace.PositiveCompacts.coe_mk -- porting note: `@[simp]` moved to a new lemma theorem carrier_eq_coe (s : PositiveCompacts Ξ±) : s.carrier = s := rfl #align topological_space.positive_compacts.carrier_eq_coe TopologicalSpace.PositiveCompacts.carrier_eq_coe @[simp] theorem coe_toCompacts (s : PositiveCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (PositiveCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.interior_nonempty.mono <| interior_mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (PositiveCompacts Ξ±) := ⟨⟨⊀, interior_univ.symm.subst univ_nonempty⟩⟩ instance : SemilatticeSup (PositiveCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (PositiveCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : PositiveCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : PositiveCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.positive_compacts.coe_top TopologicalSpace.PositiveCompacts.coe_top /-- The image of a positive compact set under a continuous open map. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (hf' : IsOpenMap f) (K : PositiveCompacts Ξ±) : PositiveCompacts Ξ² := { Compacts.map f hf K.toCompacts with interior_nonempty' := (K.interior_nonempty'.image _).mono (hf'.image_interior_subset K.toCompacts) } #align topological_space.positive_compacts.map TopologicalSpace.PositiveCompacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (hf' : IsOpenMap f) (s : PositiveCompacts Ξ±) : (s.map f hf hf' : Set Ξ²) = f '' s := rfl #align topological_space.positive_compacts.coe_map TopologicalSpace.PositiveCompacts.coe_map @[simp] theorem map_id (K : PositiveCompacts Ξ±) : K.map id continuous_id IsOpenMap.id = K := PositiveCompacts.ext <| Set.image_id _ #align topological_space.positive_compacts.map_id TopologicalSpace.PositiveCompacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f) (hg' : IsOpenMap g) (K : PositiveCompacts Ξ±) : K.map (f ∘ g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' := PositiveCompacts.ext <| Set.image_comp _ _ _ #align topological_space.positive_compacts.map_comp TopologicalSpace.PositiveCompacts.map_comp theorem _root_.exists_positiveCompacts_subset [LocallyCompactSpace Ξ±] {U : Set Ξ±} (ho : IsOpen U) (hn : U.Nonempty) : βˆƒ K : PositiveCompacts Ξ±, ↑K βŠ† U := let ⟨x, hx⟩ := hn let ⟨K, hKc, hxK, hKU⟩ := exists_compact_subset ho hx ⟨⟨⟨K, hKc⟩, ⟨x, hxK⟩⟩, hKU⟩ #align exists_positive_compacts_subset exists_positiveCompacts_subset instance [CompactSpace Ξ±] [Nonempty Ξ±] : Inhabited (PositiveCompacts Ξ±) := ⟨⊀⟩ /-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/ instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by inhabit Ξ± rcases exists_compact_mem_nhds (default : Ξ±) with ⟨K, hKc, hK⟩
exact ⟨⟨K, hKc⟩, _, mem_interior_iff_mem_nhds.2 hK⟩
/-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/ instance nonempty' [WeaklyLocallyCompactSpace α] [Nonempty α] : Nonempty (PositiveCompacts α) := by inhabit α rcases exists_compact_mem_nhds (default : α) with ⟨K, hKc, hK⟩
Mathlib.Topology.Sets.Compacts.424_0.XVs1udLPbHOIEoW
/-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/ instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±)
Mathlib_Topology_Sets_Compacts
α : Type u_1 β : Type u_2 γ : Type u_3 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β inst✝ : TopologicalSpace γ K : PositiveCompacts α L : PositiveCompacts β ⊒ Set.Nonempty (interior (Compacts.prod K.toCompacts L.toCompacts).carrier)
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by ext1 simp only [coe_map, ← image_comp, f.self_comp_symm, image_id] #align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv @[simp] theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ := Equiv.ext map_id #align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl @[simp] theorem equiv_trans (f : Ξ± β‰ƒβ‚œ Ξ²) (g : Ξ² β‰ƒβ‚œ Ξ³) : Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) := -- porting note: can no longer write `map_comp _ _ _ _` and unify Equiv.ext <| map_comp g f g.continuous f.continuous #align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans @[simp] theorem equiv_symm (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm := rfl #align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm /-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/ theorem coe_equiv_apply_eq_preimage (f : Ξ± β‰ƒβ‚œ Ξ²) (K : Compacts Ξ±) : (Compacts.equiv f K : Set Ξ²) = f.symm ⁻¹' (K : Set Ξ±) := f.toEquiv.image_eq_preimage K #align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage /-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product space. -/ protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ— Ξ²) where carrier := K Γ—Λ’ L isCompact' := IsCompact.prod K.2 L.2 #align topological_space.compacts.prod TopologicalSpace.Compacts.prod @[simp] theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod -- todo: add `pi` end Compacts /-! ### Nonempty compact sets -/ /-- The type of nonempty compact sets of a topological space. -/ structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where nonempty' : carrier.Nonempty #align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts namespace NonemptyCompacts instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s initialize_simps_projections NonemptyCompacts (carrier β†’ coe) protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.nonempty' #align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty /-- Reinterpret a nonempty compact as a closed set. -/ def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± := ⟨s, s.isCompact.isClosed⟩ #align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds @[ext] protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk -- porting note: `@[simp]` moved to `coe_toCompacts` theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s := rfl #align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe @[simp] -- porting note: new lemma theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (NonemptyCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.nonempty.mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) := ⟨⟨⊀, univ_nonempty⟩⟩ instance : SemilatticeSup (NonemptyCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : NonemptyCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : NonemptyCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top /-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with default element the singleton set containing the default element. -/ instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) := ⟨{ carrier := {default} isCompact' := isCompact_singleton nonempty' := singleton_nonempty _ }⟩ instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s := isCompact_iff_compactSpace.1 s.isCompact #align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s := s.nonempty.to_subtype #align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty /-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts` in the product space. -/ protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ— Ξ²) := { K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty } #align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod @[simp] theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod end NonemptyCompacts /-! ### Positive compact sets -/ /-- The type of compact sets with nonempty interior of a topological space. See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/ structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where interior_nonempty' : (interior carrier).Nonempty #align topological_space.positive_compacts TopologicalSpace.PositiveCompacts namespace PositiveCompacts instance : SetLike (PositiveCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : PositiveCompacts Ξ±) : Set Ξ± := s initialize_simps_projections PositiveCompacts (carrier β†’ coe) protected theorem isCompact (s : PositiveCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.positive_compacts.is_compact TopologicalSpace.PositiveCompacts.isCompact theorem interior_nonempty (s : PositiveCompacts Ξ±) : (interior (s : Set Ξ±)).Nonempty := s.interior_nonempty' #align topological_space.positive_compacts.interior_nonempty TopologicalSpace.PositiveCompacts.interior_nonempty protected theorem nonempty (s : PositiveCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.interior_nonempty.mono interior_subset #align topological_space.positive_compacts.nonempty TopologicalSpace.PositiveCompacts.nonempty /-- Reinterpret a positive compact as a nonempty compact. -/ def toNonemptyCompacts (s : PositiveCompacts Ξ±) : NonemptyCompacts Ξ± := ⟨s.toCompacts, s.nonempty⟩ #align topological_space.positive_compacts.to_nonempty_compacts TopologicalSpace.PositiveCompacts.toNonemptyCompacts @[ext] protected theorem ext {s t : PositiveCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.positive_compacts.ext TopologicalSpace.PositiveCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.positive_compacts.coe_mk TopologicalSpace.PositiveCompacts.coe_mk -- porting note: `@[simp]` moved to a new lemma theorem carrier_eq_coe (s : PositiveCompacts Ξ±) : s.carrier = s := rfl #align topological_space.positive_compacts.carrier_eq_coe TopologicalSpace.PositiveCompacts.carrier_eq_coe @[simp] theorem coe_toCompacts (s : PositiveCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (PositiveCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.interior_nonempty.mono <| interior_mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (PositiveCompacts Ξ±) := ⟨⟨⊀, interior_univ.symm.subst univ_nonempty⟩⟩ instance : SemilatticeSup (PositiveCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (PositiveCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : PositiveCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : PositiveCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.positive_compacts.coe_top TopologicalSpace.PositiveCompacts.coe_top /-- The image of a positive compact set under a continuous open map. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (hf' : IsOpenMap f) (K : PositiveCompacts Ξ±) : PositiveCompacts Ξ² := { Compacts.map f hf K.toCompacts with interior_nonempty' := (K.interior_nonempty'.image _).mono (hf'.image_interior_subset K.toCompacts) } #align topological_space.positive_compacts.map TopologicalSpace.PositiveCompacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (hf' : IsOpenMap f) (s : PositiveCompacts Ξ±) : (s.map f hf hf' : Set Ξ²) = f '' s := rfl #align topological_space.positive_compacts.coe_map TopologicalSpace.PositiveCompacts.coe_map @[simp] theorem map_id (K : PositiveCompacts Ξ±) : K.map id continuous_id IsOpenMap.id = K := PositiveCompacts.ext <| Set.image_id _ #align topological_space.positive_compacts.map_id TopologicalSpace.PositiveCompacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f) (hg' : IsOpenMap g) (K : PositiveCompacts Ξ±) : K.map (f ∘ g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' := PositiveCompacts.ext <| Set.image_comp _ _ _ #align topological_space.positive_compacts.map_comp TopologicalSpace.PositiveCompacts.map_comp theorem _root_.exists_positiveCompacts_subset [LocallyCompactSpace Ξ±] {U : Set Ξ±} (ho : IsOpen U) (hn : U.Nonempty) : βˆƒ K : PositiveCompacts Ξ±, ↑K βŠ† U := let ⟨x, hx⟩ := hn let ⟨K, hKc, hxK, hKU⟩ := exists_compact_subset ho hx ⟨⟨⟨K, hKc⟩, ⟨x, hxK⟩⟩, hKU⟩ #align exists_positive_compacts_subset exists_positiveCompacts_subset instance [CompactSpace Ξ±] [Nonempty Ξ±] : Inhabited (PositiveCompacts Ξ±) := ⟨⊀⟩ /-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/ instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by inhabit Ξ± rcases exists_compact_mem_nhds (default : Ξ±) with ⟨K, hKc, hK⟩ exact ⟨⟨K, hKc⟩, _, mem_interior_iff_mem_nhds.2 hK⟩ #align topological_space.positive_compacts.nonempty' TopologicalSpace.PositiveCompacts.nonempty' /-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts` in the product space. -/ protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) : PositiveCompacts (Ξ± Γ— Ξ²) where toCompacts := K.toCompacts.prod L.toCompacts interior_nonempty' := by
simp only [Compacts.carrier_eq_coe, Compacts.coe_prod, interior_prod_eq]
/-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts` in the product space. -/ protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) : PositiveCompacts (Ξ± Γ— Ξ²) where toCompacts := K.toCompacts.prod L.toCompacts interior_nonempty' := by
Mathlib.Topology.Sets.Compacts.431_0.XVs1udLPbHOIEoW
/-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts` in the product space. -/ protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) : PositiveCompacts (Ξ± Γ— Ξ²) where toCompacts
Mathlib_Topology_Sets_Compacts
Ξ± : Type u_1 Ξ² : Type u_2 Ξ³ : Type u_3 inst✝² : TopologicalSpace Ξ± inst✝¹ : TopologicalSpace Ξ² inst✝ : TopologicalSpace Ξ³ K : PositiveCompacts Ξ± L : PositiveCompacts Ξ² ⊒ Set.Nonempty (interior ↑K.toCompacts Γ—Λ’ interior ↑L.toCompacts)
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by ext1 simp only [coe_map, ← image_comp, f.self_comp_symm, image_id] #align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv @[simp] theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ := Equiv.ext map_id #align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl @[simp] theorem equiv_trans (f : Ξ± β‰ƒβ‚œ Ξ²) (g : Ξ² β‰ƒβ‚œ Ξ³) : Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) := -- porting note: can no longer write `map_comp _ _ _ _` and unify Equiv.ext <| map_comp g f g.continuous f.continuous #align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans @[simp] theorem equiv_symm (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm := rfl #align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm /-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/ theorem coe_equiv_apply_eq_preimage (f : Ξ± β‰ƒβ‚œ Ξ²) (K : Compacts Ξ±) : (Compacts.equiv f K : Set Ξ²) = f.symm ⁻¹' (K : Set Ξ±) := f.toEquiv.image_eq_preimage K #align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage /-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product space. -/ protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ— Ξ²) where carrier := K Γ—Λ’ L isCompact' := IsCompact.prod K.2 L.2 #align topological_space.compacts.prod TopologicalSpace.Compacts.prod @[simp] theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod -- todo: add `pi` end Compacts /-! ### Nonempty compact sets -/ /-- The type of nonempty compact sets of a topological space. -/ structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where nonempty' : carrier.Nonempty #align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts namespace NonemptyCompacts instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s initialize_simps_projections NonemptyCompacts (carrier β†’ coe) protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.nonempty' #align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty /-- Reinterpret a nonempty compact as a closed set. -/ def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± := ⟨s, s.isCompact.isClosed⟩ #align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds @[ext] protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk -- porting note: `@[simp]` moved to `coe_toCompacts` theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s := rfl #align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe @[simp] -- porting note: new lemma theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (NonemptyCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.nonempty.mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) := ⟨⟨⊀, univ_nonempty⟩⟩ instance : SemilatticeSup (NonemptyCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : NonemptyCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : NonemptyCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top /-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with default element the singleton set containing the default element. -/ instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) := ⟨{ carrier := {default} isCompact' := isCompact_singleton nonempty' := singleton_nonempty _ }⟩ instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s := isCompact_iff_compactSpace.1 s.isCompact #align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s := s.nonempty.to_subtype #align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty /-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts` in the product space. -/ protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ— Ξ²) := { K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty } #align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod @[simp] theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod end NonemptyCompacts /-! ### Positive compact sets -/ /-- The type of compact sets with nonempty interior of a topological space. See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/ structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where interior_nonempty' : (interior carrier).Nonempty #align topological_space.positive_compacts TopologicalSpace.PositiveCompacts namespace PositiveCompacts instance : SetLike (PositiveCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : PositiveCompacts Ξ±) : Set Ξ± := s initialize_simps_projections PositiveCompacts (carrier β†’ coe) protected theorem isCompact (s : PositiveCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.positive_compacts.is_compact TopologicalSpace.PositiveCompacts.isCompact theorem interior_nonempty (s : PositiveCompacts Ξ±) : (interior (s : Set Ξ±)).Nonempty := s.interior_nonempty' #align topological_space.positive_compacts.interior_nonempty TopologicalSpace.PositiveCompacts.interior_nonempty protected theorem nonempty (s : PositiveCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.interior_nonempty.mono interior_subset #align topological_space.positive_compacts.nonempty TopologicalSpace.PositiveCompacts.nonempty /-- Reinterpret a positive compact as a nonempty compact. -/ def toNonemptyCompacts (s : PositiveCompacts Ξ±) : NonemptyCompacts Ξ± := ⟨s.toCompacts, s.nonempty⟩ #align topological_space.positive_compacts.to_nonempty_compacts TopologicalSpace.PositiveCompacts.toNonemptyCompacts @[ext] protected theorem ext {s t : PositiveCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.positive_compacts.ext TopologicalSpace.PositiveCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.positive_compacts.coe_mk TopologicalSpace.PositiveCompacts.coe_mk -- porting note: `@[simp]` moved to a new lemma theorem carrier_eq_coe (s : PositiveCompacts Ξ±) : s.carrier = s := rfl #align topological_space.positive_compacts.carrier_eq_coe TopologicalSpace.PositiveCompacts.carrier_eq_coe @[simp] theorem coe_toCompacts (s : PositiveCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (PositiveCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.interior_nonempty.mono <| interior_mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (PositiveCompacts Ξ±) := ⟨⟨⊀, interior_univ.symm.subst univ_nonempty⟩⟩ instance : SemilatticeSup (PositiveCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (PositiveCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : PositiveCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : PositiveCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.positive_compacts.coe_top TopologicalSpace.PositiveCompacts.coe_top /-- The image of a positive compact set under a continuous open map. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (hf' : IsOpenMap f) (K : PositiveCompacts Ξ±) : PositiveCompacts Ξ² := { Compacts.map f hf K.toCompacts with interior_nonempty' := (K.interior_nonempty'.image _).mono (hf'.image_interior_subset K.toCompacts) } #align topological_space.positive_compacts.map TopologicalSpace.PositiveCompacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (hf' : IsOpenMap f) (s : PositiveCompacts Ξ±) : (s.map f hf hf' : Set Ξ²) = f '' s := rfl #align topological_space.positive_compacts.coe_map TopologicalSpace.PositiveCompacts.coe_map @[simp] theorem map_id (K : PositiveCompacts Ξ±) : K.map id continuous_id IsOpenMap.id = K := PositiveCompacts.ext <| Set.image_id _ #align topological_space.positive_compacts.map_id TopologicalSpace.PositiveCompacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f) (hg' : IsOpenMap g) (K : PositiveCompacts Ξ±) : K.map (f ∘ g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' := PositiveCompacts.ext <| Set.image_comp _ _ _ #align topological_space.positive_compacts.map_comp TopologicalSpace.PositiveCompacts.map_comp theorem _root_.exists_positiveCompacts_subset [LocallyCompactSpace Ξ±] {U : Set Ξ±} (ho : IsOpen U) (hn : U.Nonempty) : βˆƒ K : PositiveCompacts Ξ±, ↑K βŠ† U := let ⟨x, hx⟩ := hn let ⟨K, hKc, hxK, hKU⟩ := exists_compact_subset ho hx ⟨⟨⟨K, hKc⟩, ⟨x, hxK⟩⟩, hKU⟩ #align exists_positive_compacts_subset exists_positiveCompacts_subset instance [CompactSpace Ξ±] [Nonempty Ξ±] : Inhabited (PositiveCompacts Ξ±) := ⟨⊀⟩ /-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/ instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by inhabit Ξ± rcases exists_compact_mem_nhds (default : Ξ±) with ⟨K, hKc, hK⟩ exact ⟨⟨K, hKc⟩, _, mem_interior_iff_mem_nhds.2 hK⟩ #align topological_space.positive_compacts.nonempty' TopologicalSpace.PositiveCompacts.nonempty' /-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts` in the product space. -/ protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) : PositiveCompacts (Ξ± Γ— Ξ²) where toCompacts := K.toCompacts.prod L.toCompacts interior_nonempty' := by simp only [Compacts.carrier_eq_coe, Compacts.coe_prod, interior_prod_eq]
exact K.interior_nonempty.prod L.interior_nonempty
/-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts` in the product space. -/ protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) : PositiveCompacts (Ξ± Γ— Ξ²) where toCompacts := K.toCompacts.prod L.toCompacts interior_nonempty' := by simp only [Compacts.carrier_eq_coe, Compacts.coe_prod, interior_prod_eq]
Mathlib.Topology.Sets.Compacts.431_0.XVs1udLPbHOIEoW
/-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts` in the product space. -/ protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) : PositiveCompacts (Ξ± Γ— Ξ²) where toCompacts
Mathlib_Topology_Sets_Compacts
α : Type u_1 β : Type u_2 γ : Type u_3 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β inst✝ : TopologicalSpace γ s t : CompactOpens α h : (fun s => s.carrier) s = (fun s => s.carrier) t ⊒ s = t
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by ext1 simp only [coe_map, ← image_comp, f.self_comp_symm, image_id] #align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv @[simp] theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ := Equiv.ext map_id #align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl @[simp] theorem equiv_trans (f : Ξ± β‰ƒβ‚œ Ξ²) (g : Ξ² β‰ƒβ‚œ Ξ³) : Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) := -- porting note: can no longer write `map_comp _ _ _ _` and unify Equiv.ext <| map_comp g f g.continuous f.continuous #align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans @[simp] theorem equiv_symm (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm := rfl #align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm /-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/ theorem coe_equiv_apply_eq_preimage (f : Ξ± β‰ƒβ‚œ Ξ²) (K : Compacts Ξ±) : (Compacts.equiv f K : Set Ξ²) = f.symm ⁻¹' (K : Set Ξ±) := f.toEquiv.image_eq_preimage K #align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage /-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product space. -/ protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ— Ξ²) where carrier := K Γ—Λ’ L isCompact' := IsCompact.prod K.2 L.2 #align topological_space.compacts.prod TopologicalSpace.Compacts.prod @[simp] theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod -- todo: add `pi` end Compacts /-! ### Nonempty compact sets -/ /-- The type of nonempty compact sets of a topological space. -/ structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where nonempty' : carrier.Nonempty #align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts namespace NonemptyCompacts instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s initialize_simps_projections NonemptyCompacts (carrier β†’ coe) protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.nonempty' #align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty /-- Reinterpret a nonempty compact as a closed set. -/ def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± := ⟨s, s.isCompact.isClosed⟩ #align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds @[ext] protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk -- porting note: `@[simp]` moved to `coe_toCompacts` theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s := rfl #align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe @[simp] -- porting note: new lemma theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (NonemptyCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.nonempty.mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) := ⟨⟨⊀, univ_nonempty⟩⟩ instance : SemilatticeSup (NonemptyCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : NonemptyCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : NonemptyCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top /-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with default element the singleton set containing the default element. -/ instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) := ⟨{ carrier := {default} isCompact' := isCompact_singleton nonempty' := singleton_nonempty _ }⟩ instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s := isCompact_iff_compactSpace.1 s.isCompact #align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s := s.nonempty.to_subtype #align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty /-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts` in the product space. -/ protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ— Ξ²) := { K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty } #align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod @[simp] theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod end NonemptyCompacts /-! ### Positive compact sets -/ /-- The type of compact sets with nonempty interior of a topological space. See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/ structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where interior_nonempty' : (interior carrier).Nonempty #align topological_space.positive_compacts TopologicalSpace.PositiveCompacts namespace PositiveCompacts instance : SetLike (PositiveCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : PositiveCompacts Ξ±) : Set Ξ± := s initialize_simps_projections PositiveCompacts (carrier β†’ coe) protected theorem isCompact (s : PositiveCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.positive_compacts.is_compact TopologicalSpace.PositiveCompacts.isCompact theorem interior_nonempty (s : PositiveCompacts Ξ±) : (interior (s : Set Ξ±)).Nonempty := s.interior_nonempty' #align topological_space.positive_compacts.interior_nonempty TopologicalSpace.PositiveCompacts.interior_nonempty protected theorem nonempty (s : PositiveCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.interior_nonempty.mono interior_subset #align topological_space.positive_compacts.nonempty TopologicalSpace.PositiveCompacts.nonempty /-- Reinterpret a positive compact as a nonempty compact. -/ def toNonemptyCompacts (s : PositiveCompacts Ξ±) : NonemptyCompacts Ξ± := ⟨s.toCompacts, s.nonempty⟩ #align topological_space.positive_compacts.to_nonempty_compacts TopologicalSpace.PositiveCompacts.toNonemptyCompacts @[ext] protected theorem ext {s t : PositiveCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.positive_compacts.ext TopologicalSpace.PositiveCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.positive_compacts.coe_mk TopologicalSpace.PositiveCompacts.coe_mk -- porting note: `@[simp]` moved to a new lemma theorem carrier_eq_coe (s : PositiveCompacts Ξ±) : s.carrier = s := rfl #align topological_space.positive_compacts.carrier_eq_coe TopologicalSpace.PositiveCompacts.carrier_eq_coe @[simp] theorem coe_toCompacts (s : PositiveCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (PositiveCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.interior_nonempty.mono <| interior_mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (PositiveCompacts Ξ±) := ⟨⟨⊀, interior_univ.symm.subst univ_nonempty⟩⟩ instance : SemilatticeSup (PositiveCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (PositiveCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : PositiveCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : PositiveCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.positive_compacts.coe_top TopologicalSpace.PositiveCompacts.coe_top /-- The image of a positive compact set under a continuous open map. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (hf' : IsOpenMap f) (K : PositiveCompacts Ξ±) : PositiveCompacts Ξ² := { Compacts.map f hf K.toCompacts with interior_nonempty' := (K.interior_nonempty'.image _).mono (hf'.image_interior_subset K.toCompacts) } #align topological_space.positive_compacts.map TopologicalSpace.PositiveCompacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (hf' : IsOpenMap f) (s : PositiveCompacts Ξ±) : (s.map f hf hf' : Set Ξ²) = f '' s := rfl #align topological_space.positive_compacts.coe_map TopologicalSpace.PositiveCompacts.coe_map @[simp] theorem map_id (K : PositiveCompacts Ξ±) : K.map id continuous_id IsOpenMap.id = K := PositiveCompacts.ext <| Set.image_id _ #align topological_space.positive_compacts.map_id TopologicalSpace.PositiveCompacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f) (hg' : IsOpenMap g) (K : PositiveCompacts Ξ±) : K.map (f ∘ g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' := PositiveCompacts.ext <| Set.image_comp _ _ _ #align topological_space.positive_compacts.map_comp TopologicalSpace.PositiveCompacts.map_comp theorem _root_.exists_positiveCompacts_subset [LocallyCompactSpace Ξ±] {U : Set Ξ±} (ho : IsOpen U) (hn : U.Nonempty) : βˆƒ K : PositiveCompacts Ξ±, ↑K βŠ† U := let ⟨x, hx⟩ := hn let ⟨K, hKc, hxK, hKU⟩ := exists_compact_subset ho hx ⟨⟨⟨K, hKc⟩, ⟨x, hxK⟩⟩, hKU⟩ #align exists_positive_compacts_subset exists_positiveCompacts_subset instance [CompactSpace Ξ±] [Nonempty Ξ±] : Inhabited (PositiveCompacts Ξ±) := ⟨⊀⟩ /-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/ instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by inhabit Ξ± rcases exists_compact_mem_nhds (default : Ξ±) with ⟨K, hKc, hK⟩ exact ⟨⟨K, hKc⟩, _, mem_interior_iff_mem_nhds.2 hK⟩ #align topological_space.positive_compacts.nonempty' TopologicalSpace.PositiveCompacts.nonempty' /-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts` in the product space. -/ protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) : PositiveCompacts (Ξ± Γ— Ξ²) where toCompacts := K.toCompacts.prod L.toCompacts interior_nonempty' := by simp only [Compacts.carrier_eq_coe, Compacts.coe_prod, interior_prod_eq] exact K.interior_nonempty.prod L.interior_nonempty #align topological_space.positive_compacts.prod TopologicalSpace.PositiveCompacts.prod @[simp] theorem coe_prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.positive_compacts.coe_prod TopologicalSpace.PositiveCompacts.coe_prod end PositiveCompacts /-! ### Compact open sets -/ /-- The type of compact open sets of a topological space. This is useful in non Hausdorff contexts, in particular spectral spaces. -/ structure CompactOpens (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where isOpen' : IsOpen carrier #align topological_space.compact_opens TopologicalSpace.CompactOpens namespace CompactOpens instance : SetLike (CompactOpens Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by
obtain ⟨⟨_, _⟩, _⟩ := s
instance : SetLike (CompactOpens Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by
Mathlib.Topology.Sets.Compacts.459_0.XVs1udLPbHOIEoW
instance : SetLike (CompactOpens Ξ±) Ξ± where coe s
Mathlib_Topology_Sets_Compacts
case mk.mk α : Type u_1 β : Type u_2 γ : Type u_3 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β inst✝ : TopologicalSpace γ t : CompactOpens α carrier✝ : Set α isCompact'✝ : IsCompact carrier✝ isOpen'✝ : IsOpen { carrier := carrier✝, isCompact' := isCompact'✝ }.carrier h : (fun s => s.carrier) { toCompacts := { carrier := carrier✝, isCompact' := isCompact'✝ }, isOpen' := isOpen'✝ } = (fun s => s.carrier) t ⊒ { toCompacts := { carrier := carrier✝, isCompact' := isCompact'✝ }, isOpen' := isOpen'✝ } = t
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by ext1 simp only [coe_map, ← image_comp, f.self_comp_symm, image_id] #align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv @[simp] theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ := Equiv.ext map_id #align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl @[simp] theorem equiv_trans (f : Ξ± β‰ƒβ‚œ Ξ²) (g : Ξ² β‰ƒβ‚œ Ξ³) : Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) := -- porting note: can no longer write `map_comp _ _ _ _` and unify Equiv.ext <| map_comp g f g.continuous f.continuous #align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans @[simp] theorem equiv_symm (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm := rfl #align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm /-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/ theorem coe_equiv_apply_eq_preimage (f : Ξ± β‰ƒβ‚œ Ξ²) (K : Compacts Ξ±) : (Compacts.equiv f K : Set Ξ²) = f.symm ⁻¹' (K : Set Ξ±) := f.toEquiv.image_eq_preimage K #align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage /-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product space. -/ protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ— Ξ²) where carrier := K Γ—Λ’ L isCompact' := IsCompact.prod K.2 L.2 #align topological_space.compacts.prod TopologicalSpace.Compacts.prod @[simp] theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod -- todo: add `pi` end Compacts /-! ### Nonempty compact sets -/ /-- The type of nonempty compact sets of a topological space. -/ structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where nonempty' : carrier.Nonempty #align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts namespace NonemptyCompacts instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s initialize_simps_projections NonemptyCompacts (carrier β†’ coe) protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.nonempty' #align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty /-- Reinterpret a nonempty compact as a closed set. -/ def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± := ⟨s, s.isCompact.isClosed⟩ #align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds @[ext] protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk -- porting note: `@[simp]` moved to `coe_toCompacts` theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s := rfl #align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe @[simp] -- porting note: new lemma theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (NonemptyCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.nonempty.mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) := ⟨⟨⊀, univ_nonempty⟩⟩ instance : SemilatticeSup (NonemptyCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : NonemptyCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : NonemptyCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top /-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with default element the singleton set containing the default element. -/ instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) := ⟨{ carrier := {default} isCompact' := isCompact_singleton nonempty' := singleton_nonempty _ }⟩ instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s := isCompact_iff_compactSpace.1 s.isCompact #align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s := s.nonempty.to_subtype #align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty /-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts` in the product space. -/ protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ— Ξ²) := { K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty } #align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod @[simp] theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod end NonemptyCompacts /-! ### Positive compact sets -/ /-- The type of compact sets with nonempty interior of a topological space. See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/ structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where interior_nonempty' : (interior carrier).Nonempty #align topological_space.positive_compacts TopologicalSpace.PositiveCompacts namespace PositiveCompacts instance : SetLike (PositiveCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : PositiveCompacts Ξ±) : Set Ξ± := s initialize_simps_projections PositiveCompacts (carrier β†’ coe) protected theorem isCompact (s : PositiveCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.positive_compacts.is_compact TopologicalSpace.PositiveCompacts.isCompact theorem interior_nonempty (s : PositiveCompacts Ξ±) : (interior (s : Set Ξ±)).Nonempty := s.interior_nonempty' #align topological_space.positive_compacts.interior_nonempty TopologicalSpace.PositiveCompacts.interior_nonempty protected theorem nonempty (s : PositiveCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.interior_nonempty.mono interior_subset #align topological_space.positive_compacts.nonempty TopologicalSpace.PositiveCompacts.nonempty /-- Reinterpret a positive compact as a nonempty compact. -/ def toNonemptyCompacts (s : PositiveCompacts Ξ±) : NonemptyCompacts Ξ± := ⟨s.toCompacts, s.nonempty⟩ #align topological_space.positive_compacts.to_nonempty_compacts TopologicalSpace.PositiveCompacts.toNonemptyCompacts @[ext] protected theorem ext {s t : PositiveCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.positive_compacts.ext TopologicalSpace.PositiveCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.positive_compacts.coe_mk TopologicalSpace.PositiveCompacts.coe_mk -- porting note: `@[simp]` moved to a new lemma theorem carrier_eq_coe (s : PositiveCompacts Ξ±) : s.carrier = s := rfl #align topological_space.positive_compacts.carrier_eq_coe TopologicalSpace.PositiveCompacts.carrier_eq_coe @[simp] theorem coe_toCompacts (s : PositiveCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (PositiveCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.interior_nonempty.mono <| interior_mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (PositiveCompacts Ξ±) := ⟨⟨⊀, interior_univ.symm.subst univ_nonempty⟩⟩ instance : SemilatticeSup (PositiveCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (PositiveCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : PositiveCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : PositiveCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.positive_compacts.coe_top TopologicalSpace.PositiveCompacts.coe_top /-- The image of a positive compact set under a continuous open map. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (hf' : IsOpenMap f) (K : PositiveCompacts Ξ±) : PositiveCompacts Ξ² := { Compacts.map f hf K.toCompacts with interior_nonempty' := (K.interior_nonempty'.image _).mono (hf'.image_interior_subset K.toCompacts) } #align topological_space.positive_compacts.map TopologicalSpace.PositiveCompacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (hf' : IsOpenMap f) (s : PositiveCompacts Ξ±) : (s.map f hf hf' : Set Ξ²) = f '' s := rfl #align topological_space.positive_compacts.coe_map TopologicalSpace.PositiveCompacts.coe_map @[simp] theorem map_id (K : PositiveCompacts Ξ±) : K.map id continuous_id IsOpenMap.id = K := PositiveCompacts.ext <| Set.image_id _ #align topological_space.positive_compacts.map_id TopologicalSpace.PositiveCompacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f) (hg' : IsOpenMap g) (K : PositiveCompacts Ξ±) : K.map (f ∘ g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' := PositiveCompacts.ext <| Set.image_comp _ _ _ #align topological_space.positive_compacts.map_comp TopologicalSpace.PositiveCompacts.map_comp theorem _root_.exists_positiveCompacts_subset [LocallyCompactSpace Ξ±] {U : Set Ξ±} (ho : IsOpen U) (hn : U.Nonempty) : βˆƒ K : PositiveCompacts Ξ±, ↑K βŠ† U := let ⟨x, hx⟩ := hn let ⟨K, hKc, hxK, hKU⟩ := exists_compact_subset ho hx ⟨⟨⟨K, hKc⟩, ⟨x, hxK⟩⟩, hKU⟩ #align exists_positive_compacts_subset exists_positiveCompacts_subset instance [CompactSpace Ξ±] [Nonempty Ξ±] : Inhabited (PositiveCompacts Ξ±) := ⟨⊀⟩ /-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/ instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by inhabit Ξ± rcases exists_compact_mem_nhds (default : Ξ±) with ⟨K, hKc, hK⟩ exact ⟨⟨K, hKc⟩, _, mem_interior_iff_mem_nhds.2 hK⟩ #align topological_space.positive_compacts.nonempty' TopologicalSpace.PositiveCompacts.nonempty' /-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts` in the product space. -/ protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) : PositiveCompacts (Ξ± Γ— Ξ²) where toCompacts := K.toCompacts.prod L.toCompacts interior_nonempty' := by simp only [Compacts.carrier_eq_coe, Compacts.coe_prod, interior_prod_eq] exact K.interior_nonempty.prod L.interior_nonempty #align topological_space.positive_compacts.prod TopologicalSpace.PositiveCompacts.prod @[simp] theorem coe_prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.positive_compacts.coe_prod TopologicalSpace.PositiveCompacts.coe_prod end PositiveCompacts /-! ### Compact open sets -/ /-- The type of compact open sets of a topological space. This is useful in non Hausdorff contexts, in particular spectral spaces. -/ structure CompactOpens (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where isOpen' : IsOpen carrier #align topological_space.compact_opens TopologicalSpace.CompactOpens namespace CompactOpens instance : SetLike (CompactOpens Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s
obtain ⟨⟨_, _⟩, _⟩ := t
instance : SetLike (CompactOpens α) α where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s
Mathlib.Topology.Sets.Compacts.459_0.XVs1udLPbHOIEoW
instance : SetLike (CompactOpens Ξ±) Ξ± where coe s
Mathlib_Topology_Sets_Compacts
case mk.mk.mk.mk α : Type u_1 β : Type u_2 γ : Type u_3 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β inst✝ : TopologicalSpace γ carrier✝¹ : Set α isCompact'✝¹ : IsCompact carrier✝¹ isOpen'✝¹ : IsOpen { carrier := carrier✝¹, isCompact' := isCompact'✝¹ }.carrier carrier✝ : Set α isCompact'✝ : IsCompact carrier✝ isOpen'✝ : IsOpen { carrier := carrier✝, isCompact' := isCompact'✝ }.carrier h : (fun s => s.carrier) { toCompacts := { carrier := carrier✝¹, isCompact' := isCompact'✝¹ }, isOpen' := isOpen'✝¹ } = (fun s => s.carrier) { toCompacts := { carrier := carrier✝, isCompact' := isCompact'✝ }, isOpen' := isOpen'✝ } ⊒ { toCompacts := { carrier := carrier✝¹, isCompact' := isCompact'✝¹ }, isOpen' := isOpen'✝¹ } = { toCompacts := { carrier := carrier✝, isCompact' := isCompact'✝ }, isOpen' := isOpen'✝ }
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated #align_import topology.sets.compacts from "leanprover-community/mathlib"@"8c1b484d6a214e059531e22f1be9898ed6c1fd47" /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `Ξ±`, * `TopologicalSpace.Compacts Ξ±`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts Ξ±`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts Ξ±`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens Ξ±`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {Ξ± Ξ² Ξ³ : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [TopologicalSpace Ξ³] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (Ξ± : Type*) [TopologicalSpace Ξ±] where carrier : Set Ξ± isCompact' : IsCompact carrier #align topological_space.compacts TopologicalSpace.Compacts namespace Compacts instance : SetLike (Compacts Ξ±) Ξ± where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts Ξ±) : Set Ξ± := s initialize_simps_projections Compacts (carrier β†’ coe) protected theorem isCompact (s : Compacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact instance (K : Compacts Ξ±) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact instance : CanLift (Set Ξ±) (Compacts Ξ±) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.compacts.ext TopologicalSpace.Compacts.ext @[simp] theorem coe_mk (s : Set Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk @[simp] theorem carrier_eq_coe (s : Compacts Ξ±) : s.carrier = s := rfl #align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe instance : Sup (Compacts Ξ±) := ⟨fun s t => ⟨s βˆͺ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space Ξ±] : Inf (Compacts Ξ±) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace Ξ±] : Top (Compacts Ξ±) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts Ξ±) := βŸ¨βŸ¨βˆ…, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space Ξ±] : DistribLattice (Compacts Ξ±) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts Ξ±) := OrderBot.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl instance [CompactSpace Ξ±] : BoundedOrder (Compacts Ξ±) := BoundedOrder.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts Ξ±) := ⟨βŠ₯⟩ @[simp] theorem coe_sup (s t : Compacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup @[simp] theorem coe_inf [T2Space Ξ±] (s t : Compacts Ξ±) : (↑(s βŠ“ t) : Set Ξ±) = ↑s ∩ ↑t := rfl #align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf @[simp] theorem coe_top [CompactSpace Ξ±] : (↑(⊀ : Compacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top @[simp] theorem coe_bot : (↑(βŠ₯ : Compacts Ξ±) : Set Ξ±) = βˆ… := rfl #align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot @[simp] theorem coe_finset_sup {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ Compacts Ξ±} : (↑(s.sup f) : Set Ξ±) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr #align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup /-- The image of a compact set under a continuous function. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (K : Compacts Ξ±) : Compacts Ξ² := ⟨f '' K.1, K.2.image hf⟩ #align topological_space.compacts.map TopologicalSpace.Compacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (s : Compacts Ξ±) : (s.map f hf : Set Ξ²) = f '' s := rfl #align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map @[simp] theorem map_id (K : Compacts Ξ±) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ #align topological_space.compacts.map_id TopologicalSpace.Compacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (K : Compacts Ξ±) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ #align topological_space.compacts.map_comp TopologicalSpace.Compacts.map_comp /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts Ξ± ≃ Compacts Ξ² where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by ext1 simp only [coe_map, ← image_comp, f.self_comp_symm, image_id] #align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv @[simp] theorem equiv_refl : Compacts.equiv (Homeomorph.refl Ξ±) = Equiv.refl _ := Equiv.ext map_id #align topological_space.compacts.equiv_refl TopologicalSpace.Compacts.equiv_refl @[simp] theorem equiv_trans (f : Ξ± β‰ƒβ‚œ Ξ²) (g : Ξ² β‰ƒβ‚œ Ξ³) : Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) := -- porting note: can no longer write `map_comp _ _ _ _` and unify Equiv.ext <| map_comp g f g.continuous f.continuous #align topological_space.compacts.equiv_trans TopologicalSpace.Compacts.equiv_trans @[simp] theorem equiv_symm (f : Ξ± β‰ƒβ‚œ Ξ²) : Compacts.equiv f.symm = (Compacts.equiv f).symm := rfl #align topological_space.compacts.equiv_symm TopologicalSpace.Compacts.equiv_symm /-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/ theorem coe_equiv_apply_eq_preimage (f : Ξ± β‰ƒβ‚œ Ξ²) (K : Compacts Ξ±) : (Compacts.equiv f K : Set Ξ²) = f.symm ⁻¹' (K : Set Ξ±) := f.toEquiv.image_eq_preimage K #align topological_space.compacts.coe_equiv_apply_eq_preimage TopologicalSpace.Compacts.coe_equiv_apply_eq_preimage /-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product space. -/ protected def prod (K : Compacts Ξ±) (L : Compacts Ξ²) : Compacts (Ξ± Γ— Ξ²) where carrier := K Γ—Λ’ L isCompact' := IsCompact.prod K.2 L.2 #align topological_space.compacts.prod TopologicalSpace.Compacts.prod @[simp] theorem coe_prod (K : Compacts Ξ±) (L : Compacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod -- todo: add `pi` end Compacts /-! ### Nonempty compact sets -/ /-- The type of nonempty compact sets of a topological space. -/ structure NonemptyCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where nonempty' : carrier.Nonempty #align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts namespace NonemptyCompacts instance : SetLike (NonemptyCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : NonemptyCompacts Ξ±) : Set Ξ± := s initialize_simps_projections NonemptyCompacts (carrier β†’ coe) protected theorem isCompact (s : NonemptyCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact protected theorem nonempty (s : NonemptyCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.nonempty' #align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty /-- Reinterpret a nonempty compact as a closed set. -/ def toCloseds [T2Space Ξ±] (s : NonemptyCompacts Ξ±) : Closeds Ξ± := ⟨s, s.isCompact.isClosed⟩ #align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds @[ext] protected theorem ext {s t : NonemptyCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk -- porting note: `@[simp]` moved to `coe_toCompacts` theorem carrier_eq_coe (s : NonemptyCompacts Ξ±) : s.carrier = s := rfl #align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe @[simp] -- porting note: new lemma theorem coe_toCompacts (s : NonemptyCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (NonemptyCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.nonempty.mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (NonemptyCompacts Ξ±) := ⟨⟨⊀, univ_nonempty⟩⟩ instance : SemilatticeSup (NonemptyCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (NonemptyCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : NonemptyCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : NonemptyCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top /-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with default element the singleton set containing the default element. -/ instance [Inhabited Ξ±] : Inhabited (NonemptyCompacts Ξ±) := ⟨{ carrier := {default} isCompact' := isCompact_singleton nonempty' := singleton_nonempty _ }⟩ instance toCompactSpace {s : NonemptyCompacts Ξ±} : CompactSpace s := isCompact_iff_compactSpace.1 s.isCompact #align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace instance toNonempty {s : NonemptyCompacts Ξ±} : Nonempty s := s.nonempty.to_subtype #align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty /-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts` in the product space. -/ protected def prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : NonemptyCompacts (Ξ± Γ— Ξ²) := { K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty } #align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod @[simp] theorem coe_prod (K : NonemptyCompacts Ξ±) (L : NonemptyCompacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod end NonemptyCompacts /-! ### Positive compact sets -/ /-- The type of compact sets with nonempty interior of a topological space. See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/ structure PositiveCompacts (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where interior_nonempty' : (interior carrier).Nonempty #align topological_space.positive_compacts TopologicalSpace.PositiveCompacts namespace PositiveCompacts instance : SetLike (PositiveCompacts Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : PositiveCompacts Ξ±) : Set Ξ± := s initialize_simps_projections PositiveCompacts (carrier β†’ coe) protected theorem isCompact (s : PositiveCompacts Ξ±) : IsCompact (s : Set Ξ±) := s.isCompact' #align topological_space.positive_compacts.is_compact TopologicalSpace.PositiveCompacts.isCompact theorem interior_nonempty (s : PositiveCompacts Ξ±) : (interior (s : Set Ξ±)).Nonempty := s.interior_nonempty' #align topological_space.positive_compacts.interior_nonempty TopologicalSpace.PositiveCompacts.interior_nonempty protected theorem nonempty (s : PositiveCompacts Ξ±) : (s : Set Ξ±).Nonempty := s.interior_nonempty.mono interior_subset #align topological_space.positive_compacts.nonempty TopologicalSpace.PositiveCompacts.nonempty /-- Reinterpret a positive compact as a nonempty compact. -/ def toNonemptyCompacts (s : PositiveCompacts Ξ±) : NonemptyCompacts Ξ± := ⟨s.toCompacts, s.nonempty⟩ #align topological_space.positive_compacts.to_nonempty_compacts TopologicalSpace.PositiveCompacts.toNonemptyCompacts @[ext] protected theorem ext {s t : PositiveCompacts Ξ±} (h : (s : Set Ξ±) = t) : s = t := SetLike.ext' h #align topological_space.positive_compacts.ext TopologicalSpace.PositiveCompacts.ext @[simp] theorem coe_mk (s : Compacts Ξ±) (h) : (mk s h : Set Ξ±) = s := rfl #align topological_space.positive_compacts.coe_mk TopologicalSpace.PositiveCompacts.coe_mk -- porting note: `@[simp]` moved to a new lemma theorem carrier_eq_coe (s : PositiveCompacts Ξ±) : s.carrier = s := rfl #align topological_space.positive_compacts.carrier_eq_coe TopologicalSpace.PositiveCompacts.carrier_eq_coe @[simp] theorem coe_toCompacts (s : PositiveCompacts Ξ±) : (s.toCompacts : Set Ξ±) = s := rfl instance : Sup (PositiveCompacts Ξ±) := ⟨fun s t => ⟨s.toCompacts βŠ” t.toCompacts, s.interior_nonempty.mono <| interior_mono <| subset_union_left _ _⟩⟩ instance [CompactSpace Ξ±] [Nonempty Ξ±] : Top (PositiveCompacts Ξ±) := ⟨⟨⊀, interior_univ.symm.subst univ_nonempty⟩⟩ instance : SemilatticeSup (PositiveCompacts Ξ±) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace Ξ±] [Nonempty Ξ±] : OrderTop (PositiveCompacts Ξ±) := OrderTop.lift ((↑) : _ β†’ Set Ξ±) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : PositiveCompacts Ξ±) : (↑(s βŠ” t) : Set Ξ±) = ↑s βˆͺ ↑t := rfl #align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup @[simp] theorem coe_top [CompactSpace Ξ±] [Nonempty Ξ±] : (↑(⊀ : PositiveCompacts Ξ±) : Set Ξ±) = univ := rfl #align topological_space.positive_compacts.coe_top TopologicalSpace.PositiveCompacts.coe_top /-- The image of a positive compact set under a continuous open map. -/ protected def map (f : Ξ± β†’ Ξ²) (hf : Continuous f) (hf' : IsOpenMap f) (K : PositiveCompacts Ξ±) : PositiveCompacts Ξ² := { Compacts.map f hf K.toCompacts with interior_nonempty' := (K.interior_nonempty'.image _).mono (hf'.image_interior_subset K.toCompacts) } #align topological_space.positive_compacts.map TopologicalSpace.PositiveCompacts.map @[simp, norm_cast] theorem coe_map {f : Ξ± β†’ Ξ²} (hf : Continuous f) (hf' : IsOpenMap f) (s : PositiveCompacts Ξ±) : (s.map f hf hf' : Set Ξ²) = f '' s := rfl #align topological_space.positive_compacts.coe_map TopologicalSpace.PositiveCompacts.coe_map @[simp] theorem map_id (K : PositiveCompacts Ξ±) : K.map id continuous_id IsOpenMap.id = K := PositiveCompacts.ext <| Set.image_id _ #align topological_space.positive_compacts.map_id TopologicalSpace.PositiveCompacts.map_id theorem map_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f) (hg' : IsOpenMap g) (K : PositiveCompacts Ξ±) : K.map (f ∘ g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' := PositiveCompacts.ext <| Set.image_comp _ _ _ #align topological_space.positive_compacts.map_comp TopologicalSpace.PositiveCompacts.map_comp theorem _root_.exists_positiveCompacts_subset [LocallyCompactSpace Ξ±] {U : Set Ξ±} (ho : IsOpen U) (hn : U.Nonempty) : βˆƒ K : PositiveCompacts Ξ±, ↑K βŠ† U := let ⟨x, hx⟩ := hn let ⟨K, hKc, hxK, hKU⟩ := exists_compact_subset ho hx ⟨⟨⟨K, hKc⟩, ⟨x, hxK⟩⟩, hKU⟩ #align exists_positive_compacts_subset exists_positiveCompacts_subset instance [CompactSpace Ξ±] [Nonempty Ξ±] : Inhabited (PositiveCompacts Ξ±) := ⟨⊀⟩ /-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/ instance nonempty' [WeaklyLocallyCompactSpace Ξ±] [Nonempty Ξ±] : Nonempty (PositiveCompacts Ξ±) := by inhabit Ξ± rcases exists_compact_mem_nhds (default : Ξ±) with ⟨K, hKc, hK⟩ exact ⟨⟨K, hKc⟩, _, mem_interior_iff_mem_nhds.2 hK⟩ #align topological_space.positive_compacts.nonempty' TopologicalSpace.PositiveCompacts.nonempty' /-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts` in the product space. -/ protected def prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) : PositiveCompacts (Ξ± Γ— Ξ²) where toCompacts := K.toCompacts.prod L.toCompacts interior_nonempty' := by simp only [Compacts.carrier_eq_coe, Compacts.coe_prod, interior_prod_eq] exact K.interior_nonempty.prod L.interior_nonempty #align topological_space.positive_compacts.prod TopologicalSpace.PositiveCompacts.prod @[simp] theorem coe_prod (K : PositiveCompacts Ξ±) (L : PositiveCompacts Ξ²) : (K.prod L : Set (Ξ± Γ— Ξ²)) = (K : Set Ξ±) Γ—Λ’ (L : Set Ξ²) := rfl #align topological_space.positive_compacts.coe_prod TopologicalSpace.PositiveCompacts.coe_prod end PositiveCompacts /-! ### Compact open sets -/ /-- The type of compact open sets of a topological space. This is useful in non Hausdorff contexts, in particular spectral spaces. -/ structure CompactOpens (Ξ± : Type*) [TopologicalSpace Ξ±] extends Compacts Ξ± where isOpen' : IsOpen carrier #align topological_space.compact_opens TopologicalSpace.CompactOpens namespace CompactOpens instance : SetLike (CompactOpens Ξ±) Ξ± where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t
congr
instance : SetLike (CompactOpens α) α where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t
Mathlib.Topology.Sets.Compacts.459_0.XVs1udLPbHOIEoW
instance : SetLike (CompactOpens Ξ±) Ξ± where coe s
Mathlib_Topology_Sets_Compacts
Ξ± : Type u Ξ² : Type v Ξ³ : Type w Ξ΅ : ℝ Ξ΅0 : Ξ΅ > 0 a✝ b✝ : ℝ h : dist a✝ b✝ < Ξ΅ ⊒ dist (-a✝) (-b✝) < Ξ΅
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro -/ import Mathlib.Topology.Algebra.UniformMulAction import Mathlib.Topology.Algebra.Star import Mathlib.Topology.Algebra.Order.Field import Mathlib.Algebra.Periodic import Mathlib.Topology.Instances.Int #align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd" /-! # Topological properties of ℝ -/ noncomputable section open Classical Filter Int Metric Set TopologicalSpace Bornology open scoped Topology Uniformity Interval universe u v w variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} instance : NoncompactSpace ℝ := Int.closedEmbedding_coe_real.noncompactSpace theorem Real.uniformContinuous_add : UniformContinuous fun p : ℝ Γ— ℝ => p.1 + p.2 := Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 => let ⟨δ, Ξ΄0, Hδ⟩ := rat_add_continuous_lemma abs Ξ΅0 ⟨δ, Ξ΄0, fun h => let ⟨h₁, hβ‚‚βŸ© := max_lt_iff.1 h HΞ΄ h₁ hβ‚‚βŸ© #align real.uniform_continuous_add Real.uniformContinuous_add theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg ℝ _) := Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 => ⟨_, Ξ΅0, fun h => by
rw [dist_comm] at h
theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg ℝ _) := Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 => ⟨_, Ξ΅0, fun h => by
Mathlib.Topology.Instances.Real.38_0.cAejORboOY2cNtK
theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg ℝ _)
Mathlib_Topology_Instances_Real
Ξ± : Type u Ξ² : Type v Ξ³ : Type w Ξ΅ : ℝ Ξ΅0 : Ξ΅ > 0 a✝ b✝ : ℝ h : dist b✝ a✝ < Ξ΅ ⊒ dist (-a✝) (-b✝) < Ξ΅
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro -/ import Mathlib.Topology.Algebra.UniformMulAction import Mathlib.Topology.Algebra.Star import Mathlib.Topology.Algebra.Order.Field import Mathlib.Algebra.Periodic import Mathlib.Topology.Instances.Int #align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd" /-! # Topological properties of ℝ -/ noncomputable section open Classical Filter Int Metric Set TopologicalSpace Bornology open scoped Topology Uniformity Interval universe u v w variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} instance : NoncompactSpace ℝ := Int.closedEmbedding_coe_real.noncompactSpace theorem Real.uniformContinuous_add : UniformContinuous fun p : ℝ Γ— ℝ => p.1 + p.2 := Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 => let ⟨δ, Ξ΄0, Hδ⟩ := rat_add_continuous_lemma abs Ξ΅0 ⟨δ, Ξ΄0, fun h => let ⟨h₁, hβ‚‚βŸ© := max_lt_iff.1 h HΞ΄ h₁ hβ‚‚βŸ© #align real.uniform_continuous_add Real.uniformContinuous_add theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg ℝ _) := Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 => ⟨_, Ξ΅0, fun h => by rw [dist_comm] at h;
simpa only [Real.dist_eq, neg_sub_neg] using h
theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg ℝ _) := Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 => ⟨_, Ξ΅0, fun h => by rw [dist_comm] at h;
Mathlib.Topology.Instances.Real.38_0.cAejORboOY2cNtK
theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg ℝ _)
Mathlib_Topology_Instances_Real
Ξ± : Type u Ξ² : Type v Ξ³ : Type w ⊒ TopologicalAddGroup ℝ
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro -/ import Mathlib.Topology.Algebra.UniformMulAction import Mathlib.Topology.Algebra.Star import Mathlib.Topology.Algebra.Order.Field import Mathlib.Algebra.Periodic import Mathlib.Topology.Instances.Int #align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd" /-! # Topological properties of ℝ -/ noncomputable section open Classical Filter Int Metric Set TopologicalSpace Bornology open scoped Topology Uniformity Interval universe u v w variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} instance : NoncompactSpace ℝ := Int.closedEmbedding_coe_real.noncompactSpace theorem Real.uniformContinuous_add : UniformContinuous fun p : ℝ Γ— ℝ => p.1 + p.2 := Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 => let ⟨δ, Ξ΄0, Hδ⟩ := rat_add_continuous_lemma abs Ξ΅0 ⟨δ, Ξ΄0, fun h => let ⟨h₁, hβ‚‚βŸ© := max_lt_iff.1 h HΞ΄ h₁ hβ‚‚βŸ© #align real.uniform_continuous_add Real.uniformContinuous_add theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg ℝ _) := Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 => ⟨_, Ξ΅0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using h⟩ #align real.uniform_continuous_neg Real.uniformContinuous_neg instance : ContinuousStar ℝ := ⟨continuous_id⟩ instance : UniformAddGroup ℝ := UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg -- short-circuit type class inference instance : TopologicalAddGroup ℝ := by
infer_instance
instance : TopologicalAddGroup ℝ := by
Mathlib.Topology.Instances.Real.49_0.cAejORboOY2cNtK
instance : TopologicalAddGroup ℝ
Mathlib_Topology_Instances_Real
Ξ± : Type u Ξ² : Type v Ξ³ : Type w x r : ℝ ⊒ IsCompact (closedBall x r)
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro -/ import Mathlib.Topology.Algebra.UniformMulAction import Mathlib.Topology.Algebra.Star import Mathlib.Topology.Algebra.Order.Field import Mathlib.Algebra.Periodic import Mathlib.Topology.Instances.Int #align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd" /-! # Topological properties of ℝ -/ noncomputable section open Classical Filter Int Metric Set TopologicalSpace Bornology open scoped Topology Uniformity Interval universe u v w variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} instance : NoncompactSpace ℝ := Int.closedEmbedding_coe_real.noncompactSpace theorem Real.uniformContinuous_add : UniformContinuous fun p : ℝ Γ— ℝ => p.1 + p.2 := Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 => let ⟨δ, Ξ΄0, Hδ⟩ := rat_add_continuous_lemma abs Ξ΅0 ⟨δ, Ξ΄0, fun h => let ⟨h₁, hβ‚‚βŸ© := max_lt_iff.1 h HΞ΄ h₁ hβ‚‚βŸ© #align real.uniform_continuous_add Real.uniformContinuous_add theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg ℝ _) := Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 => ⟨_, Ξ΅0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using h⟩ #align real.uniform_continuous_neg Real.uniformContinuous_neg instance : ContinuousStar ℝ := ⟨continuous_id⟩ instance : UniformAddGroup ℝ := UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg -- short-circuit type class inference instance : TopologicalAddGroup ℝ := by infer_instance instance : TopologicalRing ℝ := inferInstance instance : TopologicalDivisionRing ℝ := inferInstance instance : ProperSpace ℝ where isCompact_closedBall x r := by
rw [Real.closedBall_eq_Icc]
instance : ProperSpace ℝ where isCompact_closedBall x r := by
Mathlib.Topology.Instances.Real.53_0.cAejORboOY2cNtK
instance : ProperSpace ℝ where isCompact_closedBall x r
Mathlib_Topology_Instances_Real
Ξ± : Type u Ξ² : Type v Ξ³ : Type w x r : ℝ ⊒ IsCompact (Icc (x - r) (x + r))
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro -/ import Mathlib.Topology.Algebra.UniformMulAction import Mathlib.Topology.Algebra.Star import Mathlib.Topology.Algebra.Order.Field import Mathlib.Algebra.Periodic import Mathlib.Topology.Instances.Int #align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd" /-! # Topological properties of ℝ -/ noncomputable section open Classical Filter Int Metric Set TopologicalSpace Bornology open scoped Topology Uniformity Interval universe u v w variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} instance : NoncompactSpace ℝ := Int.closedEmbedding_coe_real.noncompactSpace theorem Real.uniformContinuous_add : UniformContinuous fun p : ℝ Γ— ℝ => p.1 + p.2 := Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 => let ⟨δ, Ξ΄0, Hδ⟩ := rat_add_continuous_lemma abs Ξ΅0 ⟨δ, Ξ΄0, fun h => let ⟨h₁, hβ‚‚βŸ© := max_lt_iff.1 h HΞ΄ h₁ hβ‚‚βŸ© #align real.uniform_continuous_add Real.uniformContinuous_add theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg ℝ _) := Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 => ⟨_, Ξ΅0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using h⟩ #align real.uniform_continuous_neg Real.uniformContinuous_neg instance : ContinuousStar ℝ := ⟨continuous_id⟩ instance : UniformAddGroup ℝ := UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg -- short-circuit type class inference instance : TopologicalAddGroup ℝ := by infer_instance instance : TopologicalRing ℝ := inferInstance instance : TopologicalDivisionRing ℝ := inferInstance instance : ProperSpace ℝ where isCompact_closedBall x r := by rw [Real.closedBall_eq_Icc]
apply isCompact_Icc
instance : ProperSpace ℝ where isCompact_closedBall x r := by rw [Real.closedBall_eq_Icc]
Mathlib.Topology.Instances.Real.53_0.cAejORboOY2cNtK
instance : ProperSpace ℝ where isCompact_closedBall x r
Mathlib_Topology_Instances_Real
Ξ± : Type u Ξ² : Type v Ξ³ : Type w ⊒ βˆ€ u ∈ ⋃ a, ⋃ b, ⋃ (_ : a < b), {Ioo ↑a ↑b}, IsOpen u
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro -/ import Mathlib.Topology.Algebra.UniformMulAction import Mathlib.Topology.Algebra.Star import Mathlib.Topology.Algebra.Order.Field import Mathlib.Algebra.Periodic import Mathlib.Topology.Instances.Int #align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd" /-! # Topological properties of ℝ -/ noncomputable section open Classical Filter Int Metric Set TopologicalSpace Bornology open scoped Topology Uniformity Interval universe u v w variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} instance : NoncompactSpace ℝ := Int.closedEmbedding_coe_real.noncompactSpace theorem Real.uniformContinuous_add : UniformContinuous fun p : ℝ Γ— ℝ => p.1 + p.2 := Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 => let ⟨δ, Ξ΄0, Hδ⟩ := rat_add_continuous_lemma abs Ξ΅0 ⟨δ, Ξ΄0, fun h => let ⟨h₁, hβ‚‚βŸ© := max_lt_iff.1 h HΞ΄ h₁ hβ‚‚βŸ© #align real.uniform_continuous_add Real.uniformContinuous_add theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg ℝ _) := Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 => ⟨_, Ξ΅0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using h⟩ #align real.uniform_continuous_neg Real.uniformContinuous_neg instance : ContinuousStar ℝ := ⟨continuous_id⟩ instance : UniformAddGroup ℝ := UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg -- short-circuit type class inference instance : TopologicalAddGroup ℝ := by infer_instance instance : TopologicalRing ℝ := inferInstance instance : TopologicalDivisionRing ℝ := inferInstance instance : ProperSpace ℝ where isCompact_closedBall x r := by rw [Real.closedBall_eq_Icc] apply isCompact_Icc instance : SecondCountableTopology ℝ := secondCountable_of_proper theorem Real.isTopologicalBasis_Ioo_rat : @IsTopologicalBasis ℝ _ (⋃ (a : β„š) (b : β„š) (_ : a < b), {Ioo (a : ℝ) b}) := isTopologicalBasis_of_isOpen_of_nhds (by
simp (config := { contextual := true }) [isOpen_Ioo]
theorem Real.isTopologicalBasis_Ioo_rat : @IsTopologicalBasis ℝ _ (⋃ (a : β„š) (b : β„š) (_ : a < b), {Ioo (a : ℝ) b}) := isTopologicalBasis_of_isOpen_of_nhds (by
Mathlib.Topology.Instances.Real.60_0.cAejORboOY2cNtK
theorem Real.isTopologicalBasis_Ioo_rat : @IsTopologicalBasis ℝ _ (⋃ (a : β„š) (b : β„š) (_ : a < b), {Ioo (a : ℝ) b})
Mathlib_Topology_Instances_Real
Ξ± : Type u Ξ² : Type v Ξ³ : Type w a : ℝ v : Set ℝ hav : a ∈ v hv : IsOpen v l u : ℝ hl : l < a hu : a < u h : Ioo l u βŠ† v q : β„š hlq : l < ↑q hqa : ↑q < a p : β„š hap : a < ↑p hpu : ↑p < u ⊒ Ioo ↑q ↑p ∈ ⋃ a, ⋃ b, ⋃ (_ : a < b), {Ioo ↑a ↑b}
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro -/ import Mathlib.Topology.Algebra.UniformMulAction import Mathlib.Topology.Algebra.Star import Mathlib.Topology.Algebra.Order.Field import Mathlib.Algebra.Periodic import Mathlib.Topology.Instances.Int #align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd" /-! # Topological properties of ℝ -/ noncomputable section open Classical Filter Int Metric Set TopologicalSpace Bornology open scoped Topology Uniformity Interval universe u v w variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} instance : NoncompactSpace ℝ := Int.closedEmbedding_coe_real.noncompactSpace theorem Real.uniformContinuous_add : UniformContinuous fun p : ℝ Γ— ℝ => p.1 + p.2 := Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 => let ⟨δ, Ξ΄0, Hδ⟩ := rat_add_continuous_lemma abs Ξ΅0 ⟨δ, Ξ΄0, fun h => let ⟨h₁, hβ‚‚βŸ© := max_lt_iff.1 h HΞ΄ h₁ hβ‚‚βŸ© #align real.uniform_continuous_add Real.uniformContinuous_add theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg ℝ _) := Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 => ⟨_, Ξ΅0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using h⟩ #align real.uniform_continuous_neg Real.uniformContinuous_neg instance : ContinuousStar ℝ := ⟨continuous_id⟩ instance : UniformAddGroup ℝ := UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg -- short-circuit type class inference instance : TopologicalAddGroup ℝ := by infer_instance instance : TopologicalRing ℝ := inferInstance instance : TopologicalDivisionRing ℝ := inferInstance instance : ProperSpace ℝ where isCompact_closedBall x r := by rw [Real.closedBall_eq_Icc] apply isCompact_Icc instance : SecondCountableTopology ℝ := secondCountable_of_proper theorem Real.isTopologicalBasis_Ioo_rat : @IsTopologicalBasis ℝ _ (⋃ (a : β„š) (b : β„š) (_ : a < b), {Ioo (a : ℝ) b}) := isTopologicalBasis_of_isOpen_of_nhds (by simp (config := { contextual := true }) [isOpen_Ioo]) fun a v hav hv => let ⟨l, u, ⟨hl, hu⟩, h⟩ := mem_nhds_iff_exists_Ioo_subset.mp (IsOpen.mem_nhds hv hav) let ⟨q, hlq, hqa⟩ := exists_rat_btwn hl let ⟨p, hap, hpu⟩ := exists_rat_btwn hu ⟨Ioo q p, by
simp only [mem_iUnion]
theorem Real.isTopologicalBasis_Ioo_rat : @IsTopologicalBasis ℝ _ (⋃ (a : β„š) (b : β„š) (_ : a < b), {Ioo (a : ℝ) b}) := isTopologicalBasis_of_isOpen_of_nhds (by simp (config := { contextual := true }) [isOpen_Ioo]) fun a v hav hv => let ⟨l, u, ⟨hl, hu⟩, h⟩ := mem_nhds_iff_exists_Ioo_subset.mp (IsOpen.mem_nhds hv hav) let ⟨q, hlq, hqa⟩ := exists_rat_btwn hl let ⟨p, hap, hpu⟩ := exists_rat_btwn hu ⟨Ioo q p, by
Mathlib.Topology.Instances.Real.60_0.cAejORboOY2cNtK
theorem Real.isTopologicalBasis_Ioo_rat : @IsTopologicalBasis ℝ _ (⋃ (a : β„š) (b : β„š) (_ : a < b), {Ioo (a : ℝ) b})
Mathlib_Topology_Instances_Real
Ξ± : Type u Ξ² : Type v Ξ³ : Type w a : ℝ v : Set ℝ hav : a ∈ v hv : IsOpen v l u : ℝ hl : l < a hu : a < u h : Ioo l u βŠ† v q : β„š hlq : l < ↑q hqa : ↑q < a p : β„š hap : a < ↑p hpu : ↑p < u ⊒ βˆƒ i i_1, βˆƒ (_ : i < i_1), Ioo ↑q ↑p ∈ {Ioo ↑i ↑i_1}
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro -/ import Mathlib.Topology.Algebra.UniformMulAction import Mathlib.Topology.Algebra.Star import Mathlib.Topology.Algebra.Order.Field import Mathlib.Algebra.Periodic import Mathlib.Topology.Instances.Int #align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd" /-! # Topological properties of ℝ -/ noncomputable section open Classical Filter Int Metric Set TopologicalSpace Bornology open scoped Topology Uniformity Interval universe u v w variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} instance : NoncompactSpace ℝ := Int.closedEmbedding_coe_real.noncompactSpace theorem Real.uniformContinuous_add : UniformContinuous fun p : ℝ Γ— ℝ => p.1 + p.2 := Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 => let ⟨δ, Ξ΄0, Hδ⟩ := rat_add_continuous_lemma abs Ξ΅0 ⟨δ, Ξ΄0, fun h => let ⟨h₁, hβ‚‚βŸ© := max_lt_iff.1 h HΞ΄ h₁ hβ‚‚βŸ© #align real.uniform_continuous_add Real.uniformContinuous_add theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg ℝ _) := Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 => ⟨_, Ξ΅0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using h⟩ #align real.uniform_continuous_neg Real.uniformContinuous_neg instance : ContinuousStar ℝ := ⟨continuous_id⟩ instance : UniformAddGroup ℝ := UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg -- short-circuit type class inference instance : TopologicalAddGroup ℝ := by infer_instance instance : TopologicalRing ℝ := inferInstance instance : TopologicalDivisionRing ℝ := inferInstance instance : ProperSpace ℝ where isCompact_closedBall x r := by rw [Real.closedBall_eq_Icc] apply isCompact_Icc instance : SecondCountableTopology ℝ := secondCountable_of_proper theorem Real.isTopologicalBasis_Ioo_rat : @IsTopologicalBasis ℝ _ (⋃ (a : β„š) (b : β„š) (_ : a < b), {Ioo (a : ℝ) b}) := isTopologicalBasis_of_isOpen_of_nhds (by simp (config := { contextual := true }) [isOpen_Ioo]) fun a v hav hv => let ⟨l, u, ⟨hl, hu⟩, h⟩ := mem_nhds_iff_exists_Ioo_subset.mp (IsOpen.mem_nhds hv hav) let ⟨q, hlq, hqa⟩ := exists_rat_btwn hl let ⟨p, hap, hpu⟩ := exists_rat_btwn hu ⟨Ioo q p, by simp only [mem_iUnion]
exact ⟨q, p, Rat.cast_lt.1 <| hqa.trans hap, rfl⟩
theorem Real.isTopologicalBasis_Ioo_rat : @IsTopologicalBasis ℝ _ (⋃ (a : β„š) (b : β„š) (_ : a < b), {Ioo (a : ℝ) b}) := isTopologicalBasis_of_isOpen_of_nhds (by simp (config := { contextual := true }) [isOpen_Ioo]) fun a v hav hv => let ⟨l, u, ⟨hl, hu⟩, h⟩ := mem_nhds_iff_exists_Ioo_subset.mp (IsOpen.mem_nhds hv hav) let ⟨q, hlq, hqa⟩ := exists_rat_btwn hl let ⟨p, hap, hpu⟩ := exists_rat_btwn hu ⟨Ioo q p, by simp only [mem_iUnion]
Mathlib.Topology.Instances.Real.60_0.cAejORboOY2cNtK
theorem Real.isTopologicalBasis_Ioo_rat : @IsTopologicalBasis ℝ _ (⋃ (a : β„š) (b : β„š) (_ : a < b), {Ioo (a : ℝ) b})
Mathlib_Topology_Instances_Real
Ξ± : Type u Ξ² : Type v Ξ³ : Type w ⊒ cobounded ℝ = atBot βŠ” atTop
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro -/ import Mathlib.Topology.Algebra.UniformMulAction import Mathlib.Topology.Algebra.Star import Mathlib.Topology.Algebra.Order.Field import Mathlib.Algebra.Periodic import Mathlib.Topology.Instances.Int #align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd" /-! # Topological properties of ℝ -/ noncomputable section open Classical Filter Int Metric Set TopologicalSpace Bornology open scoped Topology Uniformity Interval universe u v w variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} instance : NoncompactSpace ℝ := Int.closedEmbedding_coe_real.noncompactSpace theorem Real.uniformContinuous_add : UniformContinuous fun p : ℝ Γ— ℝ => p.1 + p.2 := Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 => let ⟨δ, Ξ΄0, Hδ⟩ := rat_add_continuous_lemma abs Ξ΅0 ⟨δ, Ξ΄0, fun h => let ⟨h₁, hβ‚‚βŸ© := max_lt_iff.1 h HΞ΄ h₁ hβ‚‚βŸ© #align real.uniform_continuous_add Real.uniformContinuous_add theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg ℝ _) := Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 => ⟨_, Ξ΅0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using h⟩ #align real.uniform_continuous_neg Real.uniformContinuous_neg instance : ContinuousStar ℝ := ⟨continuous_id⟩ instance : UniformAddGroup ℝ := UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg -- short-circuit type class inference instance : TopologicalAddGroup ℝ := by infer_instance instance : TopologicalRing ℝ := inferInstance instance : TopologicalDivisionRing ℝ := inferInstance instance : ProperSpace ℝ where isCompact_closedBall x r := by rw [Real.closedBall_eq_Icc] apply isCompact_Icc instance : SecondCountableTopology ℝ := secondCountable_of_proper theorem Real.isTopologicalBasis_Ioo_rat : @IsTopologicalBasis ℝ _ (⋃ (a : β„š) (b : β„š) (_ : a < b), {Ioo (a : ℝ) b}) := isTopologicalBasis_of_isOpen_of_nhds (by simp (config := { contextual := true }) [isOpen_Ioo]) fun a v hav hv => let ⟨l, u, ⟨hl, hu⟩, h⟩ := mem_nhds_iff_exists_Ioo_subset.mp (IsOpen.mem_nhds hv hav) let ⟨q, hlq, hqa⟩ := exists_rat_btwn hl let ⟨p, hap, hpu⟩ := exists_rat_btwn hu ⟨Ioo q p, by simp only [mem_iUnion] exact ⟨q, p, Rat.cast_lt.1 <| hqa.trans hap, rfl⟩, ⟨hqa, hap⟩, fun a' ⟨hqa', ha'p⟩ => h ⟨hlq.trans hqa', ha'p.trans hpu⟩⟩ #align real.is_topological_basis_Ioo_rat Real.isTopologicalBasis_Ioo_rat @[simp] theorem Real.cobounded_eq : cobounded ℝ = atBot βŠ” atTop := by
simp only [← comap_dist_right_atTop (0 : ℝ), Real.dist_eq, sub_zero, comap_abs_atTop]
@[simp] theorem Real.cobounded_eq : cobounded ℝ = atBot βŠ” atTop := by
Mathlib.Topology.Instances.Real.73_0.cAejORboOY2cNtK
@[simp] theorem Real.cobounded_eq : cobounded ℝ = atBot βŠ” atTop
Mathlib_Topology_Instances_Real
Ξ± : Type u Ξ² : Type v Ξ³ : Type w ⊒ cocompact ℝ = atBot βŠ” atTop
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro -/ import Mathlib.Topology.Algebra.UniformMulAction import Mathlib.Topology.Algebra.Star import Mathlib.Topology.Algebra.Order.Field import Mathlib.Algebra.Periodic import Mathlib.Topology.Instances.Int #align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd" /-! # Topological properties of ℝ -/ noncomputable section open Classical Filter Int Metric Set TopologicalSpace Bornology open scoped Topology Uniformity Interval universe u v w variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} instance : NoncompactSpace ℝ := Int.closedEmbedding_coe_real.noncompactSpace theorem Real.uniformContinuous_add : UniformContinuous fun p : ℝ Γ— ℝ => p.1 + p.2 := Metric.uniformContinuous_iff.2 fun _Ξ΅ Ξ΅0 => let ⟨δ, Ξ΄0, Hδ⟩ := rat_add_continuous_lemma abs Ξ΅0 ⟨δ, Ξ΄0, fun h => let ⟨h₁, hβ‚‚βŸ© := max_lt_iff.1 h HΞ΄ h₁ hβ‚‚βŸ© #align real.uniform_continuous_add Real.uniformContinuous_add theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg ℝ _) := Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 => ⟨_, Ξ΅0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using h⟩ #align real.uniform_continuous_neg Real.uniformContinuous_neg instance : ContinuousStar ℝ := ⟨continuous_id⟩ instance : UniformAddGroup ℝ := UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg -- short-circuit type class inference instance : TopologicalAddGroup ℝ := by infer_instance instance : TopologicalRing ℝ := inferInstance instance : TopologicalDivisionRing ℝ := inferInstance instance : ProperSpace ℝ where isCompact_closedBall x r := by rw [Real.closedBall_eq_Icc] apply isCompact_Icc instance : SecondCountableTopology ℝ := secondCountable_of_proper theorem Real.isTopologicalBasis_Ioo_rat : @IsTopologicalBasis ℝ _ (⋃ (a : β„š) (b : β„š) (_ : a < b), {Ioo (a : ℝ) b}) := isTopologicalBasis_of_isOpen_of_nhds (by simp (config := { contextual := true }) [isOpen_Ioo]) fun a v hav hv => let ⟨l, u, ⟨hl, hu⟩, h⟩ := mem_nhds_iff_exists_Ioo_subset.mp (IsOpen.mem_nhds hv hav) let ⟨q, hlq, hqa⟩ := exists_rat_btwn hl let ⟨p, hap, hpu⟩ := exists_rat_btwn hu ⟨Ioo q p, by simp only [mem_iUnion] exact ⟨q, p, Rat.cast_lt.1 <| hqa.trans hap, rfl⟩, ⟨hqa, hap⟩, fun a' ⟨hqa', ha'p⟩ => h ⟨hlq.trans hqa', ha'p.trans hpu⟩⟩ #align real.is_topological_basis_Ioo_rat Real.isTopologicalBasis_Ioo_rat @[simp] theorem Real.cobounded_eq : cobounded ℝ = atBot βŠ” atTop := by simp only [← comap_dist_right_atTop (0 : ℝ), Real.dist_eq, sub_zero, comap_abs_atTop] @[simp] theorem Real.cocompact_eq : cocompact ℝ = atBot βŠ” atTop := by
rw [← cobounded_eq_cocompact, cobounded_eq]
@[simp] theorem Real.cocompact_eq : cocompact ℝ = atBot βŠ” atTop := by
Mathlib.Topology.Instances.Real.77_0.cAejORboOY2cNtK
@[simp] theorem Real.cocompact_eq : cocompact ℝ = atBot βŠ” atTop
Mathlib_Topology_Instances_Real