state
stringlengths
0
159k
srcUpToTactic
stringlengths
387
167k
nextTactic
stringlengths
3
9k
declUpToTactic
stringlengths
22
11.5k
declId
stringlengths
38
95
decl
stringlengths
16
1.89k
file_tag
stringlengths
17
73
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : 0 < y - x hyz : 0 < z - y hxz : 0 < z - x hxz' : x β‰  z a : π•œ := (z - y) / (z - x) b : π•œ := (y - x) / (z - x) ⊒ a β€’ x + b β€’ z = y
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by
field_simp
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by
Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : 0 < y - x hyz : 0 < z - y hxz : 0 < z - x hxz' : x β‰  z a : π•œ := (z - y) / (z - x) b : π•œ := (y - x) / (z - x) ⊒ (z - y) * x + (y - x) * z = y * (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp;
ring
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp;
Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : 0 < y - x hyz : 0 < z - y hxz : 0 < z - x hxz' : x β‰  z a : π•œ := (z - y) / (z - x) b : π•œ := (y - x) / (z - x) hy : a β€’ x + b β€’ z = y ⊒ f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring
have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp)
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring
Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : 0 < y - x hyz : 0 < z - y hxz : 0 < z - x hxz' : x β‰  z a : π•œ := (z - y) / (z - x) b : π•œ := (y - x) / (z - x) hy : a β€’ x + b β€’ z = y ⊒ a + b = 1
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by
field_simp
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by
Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : 0 < y - x hyz : 0 < z - y hxz : 0 < z - x hxz' : x β‰  z a : π•œ := (z - y) / (z - x) b : π•œ := (y - x) / (z - x) hy : a β€’ x + b β€’ z = y key : f (((z - y) / (z - x)) β€’ x + ((y - x) / (z - x)) β€’ z) < ((z - y) / (z - x)) β€’ f x + ((y - x) / (z - x)) β€’ f z ⊒ f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp)
rw [hy] at key
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp)
Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : 0 < y - x hyz : 0 < z - y hxz : 0 < z - x hxz' : x β‰  z a : π•œ := (z - y) / (z - x) b : π•œ := (y - x) / (z - x) hy : a β€’ x + b β€’ z = y key : f y < ((z - y) / (z - x)) β€’ f x + ((y - x) / (z - x)) β€’ f z ⊒ f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key
Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : 0 < y - x hyz : 0 < z - y hxz : 0 < z - x hxz' : x β‰  z a : π•œ := (z - y) / (z - x) b : π•œ := (y - x) / (z - x) hy : a β€’ x + b β€’ z = y key : (z - x) * f y < (z - x) * (((z - y) / (z - x)) β€’ f x + ((y - x) / (z - x)) β€’ f z) ⊒ f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key ⊒
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz
Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : 0 < y - x hyz : 0 < z - y hxz : 0 < z - x hxz' : x β‰  z a : π•œ := (z - y) / (z - x) b : π•œ := (y - x) / (z - x) hy : a β€’ x + b β€’ z = y key : f y * (z - x) < (z - y) * f x + (y - x) * f z ⊒ (f y * (z - y) + f y * (y - x)) / ((y - x) * (z - y)) < (f x * (z - y) + f z * (y - x)) / ((y - x) * (z - y))
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒
rw [div_lt_div_right]
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒
Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : 0 < y - x hyz : 0 < z - y hxz : 0 < z - x hxz' : x β‰  z a : π•œ := (z - y) / (z - x) b : π•œ := (y - x) / (z - x) hy : a β€’ x + b β€’ z = y key : f y * (z - x) < (z - y) * f x + (y - x) * f z ⊒ f y * (z - y) + f y * (y - x) < f x * (z - y) + f z * (y - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β·
linarith
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β·
Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : 0 < y - x hyz : 0 < z - y hxz : 0 < z - x hxz' : x β‰  z a : π•œ := (z - y) / (z - x) b : π•œ := (y - x) / (z - x) hy : a β€’ x + b β€’ z = y key : f y * (z - x) < (z - y) * f x + (y - x) * f z ⊒ 0 < (y - x) * (z - y)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β·
nlinarith
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β·
Mathlib.Analysis.Convex.Slope.57_0.2UqTeSfXEWgn9kZ
/-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConcaveOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z ⊒ (f z - f y) / (z - y) < (f y - f x) / (y - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
/-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
Mathlib.Analysis.Convex.Slope.83_0.2UqTeSfXEWgn9kZ
/-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConcaveOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z this : -(((-f) z - (-f) y) / (z - y)) < -(((-f) y - (-f) x) / (y - x)) ⊒ (f z - f y) / (z - y) < (f y - f x) / (y - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this
/-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
Mathlib.Analysis.Convex.Slope.83_0.2UqTeSfXEWgn9kZ
/-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : StrictConcaveOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z this : (f z - f y) / (z - y) < (f y - f x) / (y - x) ⊒ (f z - f y) / (z - y) < (f y - f x) / (y - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this
exact this
/-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this
Mathlib.Analysis.Convex.Slope.83_0.2UqTeSfXEWgn9kZ
/-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 ⊒ f (a β€’ x + b β€’ z) ≀ a β€’ f x + b β€’ f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z ⊒ f (a β€’ x + b β€’ z) ≀ a β€’ f x + b β€’ f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z
have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z ⊒ x < y
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by
rw [← one_mul x, ← hab, add_mul]
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z ⊒ a * x + b * x < y
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul]
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y ⊒ f (a β€’ x + b β€’ z) ≀ a β€’ f x + b β€’ f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y ⊒ y < z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by
rw [← one_mul z, ← hab, add_mul]
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y ⊒ y < a * z + b * z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul]
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y hyz : y < z ⊒ f (a β€’ x + b β€’ z) ≀ a β€’ f x + b β€’ f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) ⊒ f (a β€’ x + b β€’ z) ≀ a β€’ f x + b β€’ f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) hxz : 0 < z - x ⊒ f (a β€’ x + b β€’ z) ≀ a β€’ f x + b β€’ f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) hxz : 0 < z - x ⊒ (z - y) / (z - x) = a
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by
rw [eq_comm, ← sub_eq_iff_eq_add'] at hab
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : 1 - a = b y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) hxz : 0 < z - x ⊒ (z - y) / (z - x) = a
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', ← hab]
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : 1 - a = b y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) hxz : 0 < z - x ⊒ z - (a * x + (1 - a) * z) = a * (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab]
ring
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab]
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha✝ : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) hxz : 0 < z - x ha : (z - y) / (z - x) = a ⊒ f (a β€’ x + b β€’ z) ≀ a β€’ f x + b β€’ f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring
have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha✝ : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) hxz : 0 < z - x ha : (z - y) / (z - x) = a ⊒ (y - x) / (z - x) = b
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by
rw [eq_comm, ← sub_eq_iff_eq_add] at hab
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha✝ : 0 < a hb : 0 < b hab : 1 - b = a y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) hxz : 0 < z - x ha : (z - y) / (z - x) = a ⊒ (y - x) / (z - x) = b
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', ← hab]
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha✝ : 0 < a hb : 0 < b hab : 1 - b = a y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) hxz : 0 < z - x ha : (z - y) / (z - x) = a ⊒ (1 - b) * x + b * z - x = b * (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab]
ring
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab]
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha✝ : 0 < a hb✝ : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) hxz : 0 < z - x ha : (z - y) / (z - x) = a hb : (y - x) / (z - x) = b ⊒ f (a β€’ x + b β€’ z) ≀ a β€’ f x + b β€’ f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring
Mathlib.Analysis.Convex.Slope.93_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) ⊒ ConcaveOn π•œ s f
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by
rw [← neg_convexOn_iff]
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by
Mathlib.Analysis.Convex.Slope.124_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) ⊒ ConvexOn π•œ s (-f)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff]
refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff]
Mathlib.Analysis.Convex.Slope.124_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) x✝ y✝ z✝ : π•œ hx : x✝ ∈ s hz : z✝ ∈ s hxy : x✝ < y✝ hyz : y✝ < z✝ ⊒ ((-f) y✝ - (-f) x✝) / (y✝ - x✝) ≀ ((-f) z✝ - (-f) y✝) / (z✝ - y✝)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
rw [← neg_le_neg_iff]
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _
Mathlib.Analysis.Convex.Slope.124_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) x✝ y✝ z✝ : π•œ hx : x✝ ∈ s hz : z✝ ∈ s hxy : x✝ < y✝ hyz : y✝ < z✝ ⊒ -(((-f) z✝ - (-f) y✝) / (z✝ - y✝)) ≀ -(((-f) y✝ - (-f) x✝) / (y✝ - x✝))
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff]
simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff]
Mathlib.Analysis.Convex.Slope.124_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) x✝ y✝ z✝ : π•œ hx : x✝ ∈ s hz : z✝ ∈ s hxy : x✝ < y✝ hyz : y✝ < z✝ ⊒ (f z✝ - f y✝) / (z✝ - y✝) ≀ (f y✝ - f x✝) / (y✝ - x✝)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
Mathlib.Analysis.Convex.Slope.124_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 ⊒ f (a β€’ x + b β€’ z) < a β€’ f x + b β€’ f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z ⊒ f (a β€’ x + b β€’ z) < a β€’ f x + b β€’ f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z
have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z ⊒ x < y
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by
rw [← one_mul x, ← hab, add_mul]
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z ⊒ a * x + b * x < y
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul]
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y ⊒ f (a β€’ x + b β€’ z) < a β€’ f x + b β€’ f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y ⊒ y < z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by
rw [← one_mul z, ← hab, add_mul]
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y ⊒ y < a * z + b * z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul]
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y hyz : y < z ⊒ f (a β€’ x + b β€’ z) < a β€’ f x + b β€’ f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) < (f z - f y) * (y - x) ⊒ f (a β€’ x + b β€’ z) < a β€’ f x + b β€’ f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) < (f z - f y) * (y - x) hxz : 0 < z - x ⊒ f (a β€’ x + b β€’ z) < a β€’ f x + b β€’ f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) < (f z - f y) * (y - x) hxz : 0 < z - x ⊒ (z - y) / (z - x) = a
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by
rw [eq_comm, ← sub_eq_iff_eq_add'] at hab
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : 1 - a = b y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) < (f z - f y) * (y - x) hxz : 0 < z - x ⊒ (z - y) / (z - x) = a
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab
simp_rw [div_eq_iff hxz.ne', ← hab]
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha : 0 < a hb : 0 < b hab : 1 - a = b y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) < (f z - f y) * (y - x) hxz : 0 < z - x ⊒ z - (a * x + (1 - a) * z) = a * (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab]
ring
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab]
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha✝ : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) < (f z - f y) * (y - x) hxz : 0 < z - x ha : (z - y) / (z - x) = a ⊒ f (a β€’ x + b β€’ z) < a β€’ f x + b β€’ f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring
have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha✝ : 0 < a hb : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) < (f z - f y) * (y - x) hxz : 0 < z - x ha : (z - y) / (z - x) = a ⊒ (y - x) / (z - x) = b
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by
rw [eq_comm, ← sub_eq_iff_eq_add] at hab
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha✝ : 0 < a hb : 0 < b hab : 1 - b = a y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) < (f z - f y) * (y - x) hxz : 0 < z - x ha : (z - y) / (z - x) = a ⊒ (y - x) / (z - x) = b
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab
simp_rw [div_eq_iff hxz.ne', ← hab]
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha✝ : 0 < a hb : 0 < b hab : 1 - b = a y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) < (f z - f y) * (y - x) hxz : 0 < z - x ha : (z - y) / (z - x) = a ⊒ (1 - b) * x + b * z - x = b * (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab]
ring
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab]
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) x : π•œ hx : x ∈ s z : π•œ hz : z ∈ s hxz✝ : x < z a b : π•œ ha✝ : 0 < a hb✝ : 0 < b hab : a + b = 1 y : π•œ := a * x + b * z hxy : x < y hyz : y < z this : (f y - f x) * (z - y) < (f z - f y) * (y - x) hxz : 0 < z - x ha : (z - y) / (z - x) = a hb : (y - x) / (z - x) = b ⊒ f (a β€’ x + b β€’ z) < a β€’ f x + b β€’ f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring
Mathlib.Analysis.Convex.Slope.138_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) ⊒ StrictConcaveOn π•œ s f
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by
rw [← neg_strictConvexOn_iff]
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by
Mathlib.Analysis.Convex.Slope.169_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) ⊒ StrictConvexOn π•œ s (-f)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff]
refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff]
Mathlib.Analysis.Convex.Slope.169_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) x✝ y✝ z✝ : π•œ hx : x✝ ∈ s hz : z✝ ∈ s hxy : x✝ < y✝ hyz : y✝ < z✝ ⊒ ((-f) y✝ - (-f) x✝) / (y✝ - x✝) < ((-f) z✝ - (-f) y✝) / (z✝ - y✝)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
rw [← neg_lt_neg_iff]
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _
Mathlib.Analysis.Convex.Slope.169_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) x✝ y✝ z✝ : π•œ hx : x✝ ∈ s hz : z✝ ∈ s hxy : x✝ < y✝ hyz : y✝ < z✝ ⊒ -(((-f) z✝ - (-f) y✝) / (z✝ - y✝)) < -(((-f) y✝ - (-f) x✝) / (y✝ - x✝))
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff]
simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff]
Mathlib.Analysis.Convex.Slope.169_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hs : Convex π•œ s hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) x✝ y✝ z✝ : π•œ hx : x✝ ∈ s hz : z✝ ∈ s hxy : x✝ < y✝ hyz : y✝ < z✝ ⊒ (f z✝ - f y✝) / (z✝ - y✝) < (f y✝ - f x✝) / (y✝ - x✝)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
Mathlib.Analysis.Convex.Slope.169_0.2UqTeSfXEWgn9kZ
/-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z ⊒ (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by
have hxy' : 0 < y - x := by linarith
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z ⊒ 0 < y - x
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by
linarith
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x ⊒ (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith
have hyz' : 0 < z - y := by linarith
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x ⊒ 0 < z - y
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by
linarith
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y ⊒ (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y ⊒ 0 < z - x
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by
linarith
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ⊒ (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith
rw [← le_div_iff' hxz']
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ⊒ f y ≀ ((z - y) * f x + (y - x) * f z) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz']
have ha : 0 ≀ (z - y) / (z - x) := by positivity
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz']
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ⊒ 0 ≀ (z - y) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by
positivity
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 ≀ (z - y) / (z - x) ⊒ f y ≀ ((z - y) * f x + (y - x) * f z) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity
have hb : 0 ≀ (y - x) / (z - x) := by positivity
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 ≀ (z - y) / (z - x) ⊒ 0 ≀ (y - x) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by
positivity
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 ≀ (z - y) / (z - x) hb : 0 ≀ (y - x) / (z - x) ⊒ f y ≀ ((z - y) * f x + (y - x) * f z) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity
calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
case calc_1 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 ≀ (z - y) / (z - x) hb : 0 ≀ (y - x) / (z - x) ⊒ f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β·
congr 1
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β·
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
case calc_1.e_a π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 ≀ (z - y) / (z - x) hb : 0 ≀ (y - x) / (z - x) ⊒ y = (z - y) / (z - x) * x + (y - x) / (z - x) * z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1
field_simp
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
case calc_1.e_a π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 ≀ (z - y) / (z - x) hb : 0 ≀ (y - x) / (z - x) ⊒ y * (z - x) = (z - y) * x + (y - x) * z
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp
ring
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
case calc_2 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 ≀ (z - y) / (z - x) hb : 0 ≀ (y - x) / (z - x) ⊒ Div.div (z - y) (z - x) + Div.div (y - x) (z - x) = 1
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3
show (z - y) / (z - x) + (y - x) / (z - x) = 1
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
case calc_2 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 ≀ (z - y) / (z - x) hb : 0 ≀ (y - x) / (z - x) ⊒ (z - y) / (z - x) + (y - x) / (z - x) = 1
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1
field_simp
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
case calc_3 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hyz' : 0 < z - y hxz' : 0 < z - x ha : 0 ≀ (z - y) / (z - x) hb : 0 ≀ (y - x) / (z - x) ⊒ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z = ((z - y) * f x + (y - x) * f z) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β·
field_simp
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β·
Mathlib.Analysis.Convex.Slope.229_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z ⊒ (f y - f x) / (y - x) ≀ (f z - f x) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by
have hxy' : 0 < y - x := by linarith
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by
Mathlib.Analysis.Convex.Slope.250_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z ⊒ 0 < y - x
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by
linarith
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by
Mathlib.Analysis.Convex.Slope.250_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x ⊒ (f y - f x) / (y - x) ≀ (f z - f x) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith
have hxz' : 0 < z - x := by linarith
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith
Mathlib.Analysis.Convex.Slope.250_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x ⊒ 0 < z - x
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by
linarith
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by
Mathlib.Analysis.Convex.Slope.250_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hxz' : 0 < z - x ⊒ (f y - f x) / (y - x) ≀ (f z - f x) / (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxy' hxz']
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith
Mathlib.Analysis.Convex.Slope.250_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hxy' : 0 < y - x hxz' : 0 < z - x ⊒ (f y - f x) * (z - x) ≀ (f z - f x) * (y - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz']
Mathlib.Analysis.Convex.Slope.250_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z ⊒ (f z - f x) / (z - x) ≀ (f z - f y) / (z - y)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by
have hyz' : 0 < z - y := by linarith
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by
Mathlib.Analysis.Convex.Slope.258_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z ⊒ 0 < z - y
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by
linarith
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by
Mathlib.Analysis.Convex.Slope.258_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hyz' : 0 < z - y ⊒ (f z - f x) / (z - x) ≀ (f z - f y) / (z - y)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith
have hxz' : 0 < z - x := by linarith
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith
Mathlib.Analysis.Convex.Slope.258_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hyz' : 0 < z - y ⊒ 0 < z - x
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by
linarith
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by
Mathlib.Analysis.Convex.Slope.258_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hyz' : 0 < z - y hxz' : 0 < z - x ⊒ (f z - f x) / (z - x) ≀ (f z - f y) / (z - y)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith
rw [div_le_div_iff hxz' hyz']
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith
Mathlib.Analysis.Convex.Slope.258_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f x y z : π•œ hx : x ∈ s hz : z ∈ s hxy : x < y hyz : y < z hyz' : 0 < z - y hxz' : 0 < z - x ⊒ (f z - f x) * (z - y) ≀ (f z - f y) * (z - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz']
linarith only [hf.secant_mono_aux1 hx hz hxy hyz]
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz']
Mathlib.Analysis.Convex.Slope.258_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y)
Mathlib_Analysis_Convex_Slope
π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa : x β‰  a hya : y β‰  a hxy : x ≀ y ⊒ (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by
rcases eq_or_lt_of_le hxy with (rfl | hxy)
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by
Mathlib.Analysis.Convex.Slope.266_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case inl π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f a x : π•œ ha : a ∈ s hx : x ∈ s hxa : x β‰  a hy : x ∈ s hya : x β‰  a hxy : x ≀ x ⊒ (f x - f a) / (x - a) ≀ (f x - f a) / (x - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β·
simp
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β·
Mathlib.Analysis.Convex.Slope.266_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case inr π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa : x β‰  a hya : y β‰  a hxy✝ : x ≀ y hxy : x < y ⊒ (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp
cases' lt_or_gt_of_ne hxa with hxa hxa
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp
Mathlib.Analysis.Convex.Slope.266_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case inr.inl π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya : y β‰  a hxy✝ : x ≀ y hxy : x < y hxa : x < a ⊒ (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β·
cases' lt_or_gt_of_ne hya with hya hya
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β·
Mathlib.Analysis.Convex.Slope.266_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case inr.inl.inl π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya✝ : y β‰  a hxy✝ : x ≀ y hxy : x < y hxa : x < a hya : y < a ⊒ (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β·
convert hf.secant_mono_aux3 hx ha hxy hya using 1
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β·
Mathlib.Analysis.Convex.Slope.266_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case h.e'_3 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya✝ : y β‰  a hxy✝ : x ≀ y hxy : x < y hxa : x < a hya : y < a ⊒ (f x - f a) / (x - a) = (f a - f x) / (a - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;>
rw [← neg_div_neg_eq]
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;>
Mathlib.Analysis.Convex.Slope.266_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case h.e'_4 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya✝ : y β‰  a hxy✝ : x ≀ y hxy : x < y hxa : x < a hya : y < a ⊒ (f y - f a) / (y - a) = (f a - f y) / (a - y)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;>
rw [← neg_div_neg_eq]
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;>
Mathlib.Analysis.Convex.Slope.266_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case h.e'_3 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya✝ : y β‰  a hxy✝ : x ≀ y hxy : x < y hxa : x < a hya : y < a ⊒ -(f x - f a) / -(x - a) = (f a - f x) / (a - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;>
field_simp
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;>
Mathlib.Analysis.Convex.Slope.266_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case h.e'_4 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya✝ : y β‰  a hxy✝ : x ≀ y hxy : x < y hxa : x < a hya : y < a ⊒ -(f y - f a) / -(y - a) = (f a - f y) / (a - y)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;>
field_simp
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;>
Mathlib.Analysis.Convex.Slope.266_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case inr.inl.inr π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya✝ : y β‰  a hxy✝ : x ≀ y hxy : x < y hxa : x < a hya : y > a ⊒ (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β·
convert hf.slope_mono_adjacent hx hy hxa hya using 1
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β·
Mathlib.Analysis.Convex.Slope.266_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope
case h.e'_3 π•œ : Type u_1 inst✝ : LinearOrderedField π•œ s : Set π•œ f : π•œ β†’ π•œ hf : ConvexOn π•œ s f a x y : π•œ ha : a ∈ s hx : x ∈ s hy : y ∈ s hxa✝ : x β‰  a hya✝ : y β‰  a hxy✝ : x ≀ y hxy : x < y hxa : x < a hya : y > a ⊒ (f x - f a) / (x - a) = (f a - f x) / (a - x)
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo JaffrΓ© -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {π•œ : Type*} [LinearOrderedField π•œ] {s : Set π•œ} {f : π•œ β†’ π•œ} /-- If `f : π•œ β†’ π•œ` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≀ f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz (show 0 ≀ a by apply div_nonneg <;> linarith) (show 0 ≀ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [mul_comm (z - x) _] at key ⊒ rw [div_le_div_right] Β· linarith Β· nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : π•œ β†’ π•œ` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : π•œ β†’ π•œ` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊒ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a β€’ x + b β€’ z = y := by field_simp; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊒ rw [div_lt_div_right] Β· linarith Β· nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : π•œ β†’ π•œ` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : ConvexOn π•œ s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≀ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : ConcaveOn π•œ s f := by rw [← neg_convexOn_iff] refine' convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn π•œ s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this #align strict_convex_on_of_slope_strict_mono_adjacent strictConvexOn_of_slope_strict_mono_adjacent /-- If for any three points `x < y < z`, the slope of the secant line of `f : π•œ β†’ π•œ` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex π•œ s) (hf : βˆ€ {x y z : π•œ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn π•œ s f := by rw [← neg_strictConvexOn_iff] refine' strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => _ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz #align strict_concave_on_of_slope_strict_anti_adjacent strictConcaveOn_of_slope_strict_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align convex_on_iff_slope_mono_adjacent convexOn_iff_slope_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align concave_on_iff_slope_anti_adjacent concaveOn_iff_slope_anti_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_convex_on_iff_slope_strict_mono_adjacent strictConvexOn_iff_slope_strict_mono_adjacent /-- A function `f : π•œ β†’ π•œ` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn π•œ s f ↔ Convex π•œ s ∧ βˆ€ ⦃x y z : π•œβ¦„, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ #align strict_concave_on_iff_slope_strict_anti_adjacent strictConcaveOn_iff_slope_strict_anti_adjacent theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≀ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≀ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ Β· congr 1 field_simp ring Β· -- Porting note: this `show` wasn't needed in Lean 3 show (z - y) / (z - x) + (y - x) / (z - x) = 1 field_simp Β· field_simp #align convex_on.secant_mono_aux1 ConvexOn.secant_mono_aux1 theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux2 ConvexOn.secant_mono_aux2 theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn π•œ s f) {x y z : π•œ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≀ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] #align convex_on.secant_mono_aux3 ConvexOn.secant_mono_aux3 theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
rw [← neg_div_neg_eq]
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) Β· simp cases' lt_or_gt_of_ne hxa with hxa hxa Β· cases' lt_or_gt_of_ne hya with hya hya Β· convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1
Mathlib.Analysis.Convex.Slope.266_0.2UqTeSfXEWgn9kZ
theorem ConvexOn.secant_mono (hf : ConvexOn π•œ s f) {a x y : π•œ} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x β‰  a) (hya : y β‰  a) (hxy : x ≀ y) : (f x - f a) / (x - a) ≀ (f y - f a) / (y - a)
Mathlib_Analysis_Convex_Slope