state
stringlengths
0
159k
srcUpToTactic
stringlengths
387
167k
nextTactic
stringlengths
3
9k
declUpToTactic
stringlengths
22
11.5k
declId
stringlengths
38
95
decl
stringlengths
16
1.89k
file_tag
stringlengths
17
73
case bound E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ ℝ a b : ℝ hf : ContinuousOn f (Icc a b) B B' : ℝ β†’ ℝ ha : f a ≀ B a hB : ContinuousOn B (Icc a b) hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, βˆ€ (r : ℝ), B' x < r β†’ βˆƒαΆ  (z : ℝ) in 𝓝[>] x, slope f x z < r x✝ : ℝ hx : x✝ ∈ Icc a b r : ℝ hr : r > 0 x : ℝ a✝¹ : x ∈ Ico a b a✝ : f x = B x + r * (x - a) ⊒ B' x < B' x + r
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one]
exact (lt_add_iff_pos_right _).2 hr
/-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one]
Mathlib.Analysis.Calculus.MeanValue.149_0.ReDurB0qNQAwk9I
/-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x
Mathlib_Analysis_Calculus_MeanValue
case a E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ ℝ a b : ℝ hf : ContinuousOn f (Icc a b) B B' : ℝ β†’ ℝ ha : f a ≀ B a hB : ContinuousOn B (Icc a b) hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, βˆ€ (r : ℝ), B' x < r β†’ βˆƒαΆ  (z : ℝ) in 𝓝[>] x, slope f x z < r x : ℝ hx : x ∈ Icc a b r : ℝ hr : r > 0 ⊒ x ∈ Icc a b
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr
exact hx
/-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr
Mathlib.Analysis.Calculus.MeanValue.149_0.ReDurB0qNQAwk9I
/-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ ℝ a b : ℝ hf : ContinuousOn f (Icc a b) B B' : ℝ β†’ ℝ ha : f a ≀ B a hB : ContinuousOn B (Icc a b) hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, βˆ€ (r : ℝ), B' x < r β†’ βˆƒαΆ  (z : ℝ) in 𝓝[>] x, slope f x z < r Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) ⊒ βˆ€ ⦃x : ℝ⦄, x ∈ Icc a b β†’ f x ≀ B x
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx
intro x hx
/-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx
Mathlib.Analysis.Calculus.MeanValue.149_0.ReDurB0qNQAwk9I
/-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ ℝ a b : ℝ hf : ContinuousOn f (Icc a b) B B' : ℝ β†’ ℝ ha : f a ≀ B a hB : ContinuousOn B (Icc a b) hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, βˆ€ (r : ℝ), B' x < r β†’ βˆƒαΆ  (z : ℝ) in 𝓝[>] x, slope f x z < r Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) x : ℝ hx : x ∈ Icc a b ⊒ f x ≀ B x
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx
have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const)
/-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx
Mathlib.Analysis.Calculus.MeanValue.149_0.ReDurB0qNQAwk9I
/-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ ℝ a b : ℝ hf : ContinuousOn f (Icc a b) B B' : ℝ β†’ ℝ ha : f a ≀ B a hB : ContinuousOn B (Icc a b) hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, βˆ€ (r : ℝ), B' x < r β†’ βˆƒαΆ  (z : ℝ) in 𝓝[>] x, slope f x z < r Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) x : ℝ hx : x ∈ Icc a b this : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 ⊒ f x ≀ B x
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const)
convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1
/-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const)
Mathlib.Analysis.Calculus.MeanValue.149_0.ReDurB0qNQAwk9I
/-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x
Mathlib_Analysis_Calculus_MeanValue
case h.e'_4 E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ ℝ a b : ℝ hf : ContinuousOn f (Icc a b) B B' : ℝ β†’ ℝ ha : f a ≀ B a hB : ContinuousOn B (Icc a b) hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, βˆ€ (r : ℝ), B' x < r β†’ βˆƒαΆ  (z : ℝ) in 𝓝[>] x, slope f x z < r Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) x : ℝ hx : x ∈ Icc a b this : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 ⊒ B x = B x + 0 * (x - a)
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;>
simp
/-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;>
Mathlib.Analysis.Calculus.MeanValue.149_0.ReDurB0qNQAwk9I
/-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ ℝ a b : ℝ hf : ContinuousOn f (Icc a b) B B' : ℝ β†’ ℝ ha : f a ≀ B a hB : ContinuousOn B (Icc a b) hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, βˆ€ (r : ℝ), B' x < r β†’ βˆƒαΆ  (z : ℝ) in 𝓝[>] x, slope f x z < r Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) x : ℝ hx : x ∈ Icc a b this : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 ⊒ 0 ∈ closure (Ioi 0)
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;>
simp
/-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;>
Mathlib.Analysis.Calculus.MeanValue.149_0.ReDurB0qNQAwk9I
/-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' : ℝ β†’ E C : ℝ hf : ContinuousOn f (Icc a b) hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C ⊒ βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by
let g x := f x - f a
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by
Mathlib.Analysis.Calculus.MeanValue.337_0.ReDurB0qNQAwk9I
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' : ℝ β†’ E C : ℝ hf : ContinuousOn f (Icc a b) hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C g : ℝ β†’ E := fun x => f x - f a ⊒ βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a
have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a
Mathlib.Analysis.Calculus.MeanValue.337_0.ReDurB0qNQAwk9I
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' : ℝ β†’ E C : ℝ hf : ContinuousOn f (Icc a b) hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C g : ℝ β†’ E := fun x => f x - f a hg : ContinuousOn g (Icc a b) ⊒ βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const
have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _)
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const
Mathlib.Analysis.Calculus.MeanValue.337_0.ReDurB0qNQAwk9I
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' : ℝ β†’ E C : ℝ hf : ContinuousOn f (Icc a b) hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C g : ℝ β†’ E := fun x => f x - f a hg : ContinuousOn g (Icc a b) ⊒ βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by
intro x hx
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by
Mathlib.Analysis.Calculus.MeanValue.337_0.ReDurB0qNQAwk9I
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' : ℝ β†’ E C : ℝ hf : ContinuousOn f (Icc a b) hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C g : ℝ β†’ E := fun x => f x - f a hg : ContinuousOn g (Icc a b) x : ℝ hx : x ∈ Ico a b ⊒ HasDerivWithinAt g (f' x) (Ici x) x
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx
simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _)
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx
Mathlib.Analysis.Calculus.MeanValue.337_0.ReDurB0qNQAwk9I
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' : ℝ β†’ E C : ℝ hf : ContinuousOn f (Icc a b) hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C g : ℝ β†’ E := fun x => f x - f a hg : ContinuousOn g (Icc a b) hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x ⊒ βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _)
let B x := C * (x - a)
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _)
Mathlib.Analysis.Calculus.MeanValue.337_0.ReDurB0qNQAwk9I
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' : ℝ β†’ E C : ℝ hf : ContinuousOn f (Icc a b) hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C g : ℝ β†’ E := fun x => f x - f a hg : ContinuousOn g (Icc a b) hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x B : ℝ β†’ ℝ := fun x => C * (x - a) ⊒ βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a)
have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a))
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a)
Mathlib.Analysis.Calculus.MeanValue.337_0.ReDurB0qNQAwk9I
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' : ℝ β†’ E C : ℝ hf : ContinuousOn f (Icc a b) hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C g : ℝ β†’ E := fun x => f x - f a hg : ContinuousOn g (Icc a b) hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x B : ℝ β†’ ℝ := fun x => C * (x - a) ⊒ βˆ€ (x : ℝ), HasDerivAt B C x
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by
intro x
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by
Mathlib.Analysis.Calculus.MeanValue.337_0.ReDurB0qNQAwk9I
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' : ℝ β†’ E C : ℝ hf : ContinuousOn f (Icc a b) hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C g : ℝ β†’ E := fun x => f x - f a hg : ContinuousOn g (Icc a b) hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x B : ℝ β†’ ℝ := fun x => C * (x - a) x : ℝ ⊒ HasDerivAt B C x
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x
simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a))
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x
Mathlib.Analysis.Calculus.MeanValue.337_0.ReDurB0qNQAwk9I
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' : ℝ β†’ E C : ℝ hf : ContinuousOn f (Icc a b) hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C g : ℝ β†’ E := fun x => f x - f a hg : ContinuousOn g (Icc a b) hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x B : ℝ β†’ ℝ := fun x => C * (x - a) hB : βˆ€ (x : ℝ), HasDerivAt B C x ⊒ βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a))
convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a))
Mathlib.Analysis.Calculus.MeanValue.337_0.ReDurB0qNQAwk9I
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' : ℝ β†’ E C : ℝ hf : ContinuousOn f (Icc a b) hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C g : ℝ β†’ E := fun x => f x - f a hg : ContinuousOn g (Icc a b) hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x B : ℝ β†’ ℝ := fun x => C * (x - a) hB : βˆ€ (x : ℝ), HasDerivAt B C x ⊒ β€–g aβ€– ≀ B a
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound
simp only
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound
Mathlib.Analysis.Calculus.MeanValue.337_0.ReDurB0qNQAwk9I
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' : ℝ β†’ E C : ℝ hf : ContinuousOn f (Icc a b) hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C g : ℝ β†’ E := fun x => f x - f a hg : ContinuousOn g (Icc a b) hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x B : ℝ β†’ ℝ := fun x => C * (x - a) hB : βˆ€ (x : ℝ), HasDerivAt B C x ⊒ β€–f a - f aβ€– ≀ C * (a - a)
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only;
rw [sub_self, norm_zero, sub_self, mul_zero]
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only;
Mathlib.Analysis.Calculus.MeanValue.337_0.ReDurB0qNQAwk9I
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' : ℝ β†’ E C : ℝ hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C ⊒ βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by
refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by
Mathlib.Analysis.Calculus.MeanValue.355_0.ReDurB0qNQAwk9I
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' : ℝ β†’ E C : ℝ hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C x : ℝ hx : x ∈ Ico a b ⊒ HasDerivWithinAt (fun x => f x) (f' x) (Ici x) x
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound
exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx)
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound
Mathlib.Analysis.Calculus.MeanValue.355_0.ReDurB0qNQAwk9I
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b C : ℝ hf : DifferentiableOn ℝ f (Icc a b) bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C ⊒ βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by
refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by
Mathlib.Analysis.Calculus.MeanValue.367_0.ReDurB0qNQAwk9I
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b C : ℝ hf : DifferentiableOn ℝ f (Icc a b) bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C ⊒ βˆ€ x ∈ Icc a b, HasDerivWithinAt (fun x => f x) (derivWithin f (Icc a b) x) (Icc a b) x
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound
exact fun x hx => (hf x hx).hasDerivWithinAt
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound
Mathlib.Analysis.Calculus.MeanValue.367_0.ReDurB0qNQAwk9I
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a)
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' : ℝ β†’ E C : ℝ hf : βˆ€ x ∈ Icc 0 1, HasDerivWithinAt f (f' x) (Icc 0 1) x bound : βˆ€ x ∈ Ico 0 1, β€–f' xβ€– ≀ C ⊒ β€–f 1 - f 0β€– ≀ C
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by
simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one)
/-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by
Mathlib.Analysis.Calculus.MeanValue.377_0.ReDurB0qNQAwk9I
/-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b C : ℝ hf : DifferentiableOn ℝ f (Icc 0 1) bound : βˆ€ x ∈ Ico 0 1, β€–derivWithin f (Icc 0 1) xβ€– ≀ C ⊒ β€–f 1 - f 0β€– ≀ C
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by
simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one)
/-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by
Mathlib.Analysis.Calculus.MeanValue.387_0.ReDurB0qNQAwk9I
/-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ hcont : ContinuousOn f (Icc a b) hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x ⊒ βˆ€ x ∈ Icc a b, f x = f a
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by
have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx
theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by
Mathlib.Analysis.Calculus.MeanValue.396_0.ReDurB0qNQAwk9I
theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ hcont : ContinuousOn f (Icc a b) hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x this : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) ⊒ βˆ€ x ∈ Icc a b, f x = f a
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx
simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this
theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx
Mathlib.Analysis.Calculus.MeanValue.396_0.ReDurB0qNQAwk9I
theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ hdiff : DifferentiableOn ℝ f (Icc a b) hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0 ⊒ βˆ€ x ∈ Icc a b, f x = f a
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by
have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx
theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by
Mathlib.Analysis.Calculus.MeanValue.403_0.ReDurB0qNQAwk9I
theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ hdiff : DifferentiableOn ℝ f (Icc a b) hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0 ⊒ βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by
simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx
theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by
Mathlib.Analysis.Calculus.MeanValue.403_0.ReDurB0qNQAwk9I
theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ hdiff : DifferentiableOn ℝ f (Icc a b) hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0 H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 ⊒ βˆ€ x ∈ Icc a b, f x = f a
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx
simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx
theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx
Mathlib.Analysis.Calculus.MeanValue.403_0.ReDurB0qNQAwk9I
theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' g : ℝ β†’ E derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x fcont : ContinuousOn f (Icc a b) gcont : ContinuousOn g (Icc a b) hi : f a = g a ⊒ βˆ€ y ∈ Icc a b, f y = g y
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by
simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒
/-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by
Mathlib.Analysis.Calculus.MeanValue.413_0.ReDurB0qNQAwk9I
/-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' g : ℝ β†’ E derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x fcont : ContinuousOn f (Icc a b) gcont : ContinuousOn g (Icc a b) hi : f a - g a = 0 ⊒ βˆ€ y ∈ Icc a b, f y - g y = 0
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒
exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy)
/-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒
Mathlib.Analysis.Calculus.MeanValue.413_0.ReDurB0qNQAwk9I
/-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' g : ℝ β†’ E derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x fcont : ContinuousOn f (Icc a b) gcont : ContinuousOn g (Icc a b) hi : f a - g a = 0 y : ℝ hy : y ∈ Ico a b ⊒ HasDerivWithinAt (fun y => f y - g y) 0 (Ici y) y
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by
simpa only [sub_self] using (derivf y hy).sub (derivg y hy)
/-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by
Mathlib.Analysis.Calculus.MeanValue.413_0.ReDurB0qNQAwk9I
/-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' g : ℝ β†’ E fdiff : DifferentiableOn ℝ f (Icc a b) gdiff : DifferentiableOn ℝ g (Icc a b) hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b) hi : f a = g a ⊒ βˆ€ y ∈ Icc a b, f y = g y
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by
have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy)
/-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by
Mathlib.Analysis.Calculus.MeanValue.423_0.ReDurB0qNQAwk9I
/-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' g : ℝ β†’ E fdiff : DifferentiableOn ℝ f (Icc a b) gdiff : DifferentiableOn ℝ g (Icc a b) hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b) hi : f a = g a A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y ⊒ βˆ€ y ∈ Icc a b, f y = g y
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy)
have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy)
/-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy)
Mathlib.Analysis.Calculus.MeanValue.423_0.ReDurB0qNQAwk9I
/-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f : ℝ β†’ E a b : ℝ f' g : ℝ β†’ E fdiff : DifferentiableOn ℝ f (Icc a b) gdiff : DifferentiableOn ℝ g (Icc a b) hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b) hi : f a = g a A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y ⊒ βˆ€ y ∈ Icc a b, f y = g y
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy)
exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi
/-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy)
Mathlib.Analysis.Calculus.MeanValue.423_0.ReDurB0qNQAwk9I
/-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C hs : Convex ℝ s xs : x ∈ s ys : y ∈ s ⊒ β€–f y - f xβ€– ≀ C * β€–y - xβ€–
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by
letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by
Mathlib.Analysis.Calculus.MeanValue.455_0.ReDurB0qNQAwk9I
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€–
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C hs : Convex ℝ s xs : x ∈ s ys : y ∈ s this : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G ⊒ β€–f y - f xβ€– ≀ C * β€–y - xβ€–
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/
set g := (AffineMap.lineMap x y : ℝ β†’ E)
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/
Mathlib.Analysis.Calculus.MeanValue.455_0.ReDurB0qNQAwk9I
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€–
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g✝ : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C hs : Convex ℝ s xs : x ∈ s ys : y ∈ s this : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G g : ℝ β†’ E := ⇑(AffineMap.lineMap x y) ⊒ β€–f y - f xβ€– ≀ C * β€–y - xβ€–
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E)
have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E)
Mathlib.Analysis.Calculus.MeanValue.455_0.ReDurB0qNQAwk9I
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€–
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g✝ : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C hs : Convex ℝ s xs : x ∈ s ys : y ∈ s this : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G g : ℝ β†’ E := ⇑(AffineMap.lineMap x y) segm : MapsTo g (Icc 0 1) s ⊒ β€–f y - f xβ€– ≀ C * β€–y - xβ€–
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys
have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys
Mathlib.Analysis.Calculus.MeanValue.455_0.ReDurB0qNQAwk9I
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€–
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g✝ : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C hs : Convex ℝ s xs : x ∈ s ys : y ∈ s this : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G g : ℝ β†’ E := ⇑(AffineMap.lineMap x y) segm : MapsTo g (Icc 0 1) s t : ℝ ht : t ∈ Icc 0 1 ⊒ HasDerivWithinAt (f ∘ g) ((f' (g t)) (y - x)) (Icc 0 1) t
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by
simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by
Mathlib.Analysis.Calculus.MeanValue.455_0.ReDurB0qNQAwk9I
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€–
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g✝ : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C hs : Convex ℝ s xs : x ∈ s ys : y ∈ s this : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G g : ℝ β†’ E := ⇑(AffineMap.lineMap x y) segm : MapsTo g (Icc 0 1) s hD : βˆ€ t ∈ Icc 0 1, HasDerivWithinAt (f ∘ g) ((f' (g t)) (y - x)) (Icc 0 1) t ⊒ β€–f y - f xβ€– ≀ C * β€–y - xβ€–
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm
have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm
Mathlib.Analysis.Calculus.MeanValue.455_0.ReDurB0qNQAwk9I
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€–
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g✝ : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound✝ : βˆ€ x ∈ s, β€–f' xβ€– ≀ C hs : Convex ℝ s xs : x ∈ s ys : y ∈ s this : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G g : ℝ β†’ E := ⇑(AffineMap.lineMap x y) segm : MapsTo g (Icc 0 1) s hD : βˆ€ t ∈ Icc 0 1, HasDerivWithinAt (f ∘ g) ((f' (g t)) (y - x)) (Icc 0 1) t bound : βˆ€ t ∈ Ico 0 1, β€–(f' (g t)) (y - x)β€– ≀ C * β€–y - xβ€– ⊒ β€–f y - f xβ€– ≀ C * β€–y - xβ€–
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _
simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _
Mathlib.Analysis.Calculus.MeanValue.455_0.ReDurB0qNQAwk9I
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€–
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g : E β†’ G C✝ : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G C : ℝβ‰₯0 hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C hs : Convex ℝ s ⊒ LipschitzOnWith C f s
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by
rw [lipschitzOnWith_iff_norm_sub_le]
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by
Mathlib.Analysis.Calculus.MeanValue.476_0.ReDurB0qNQAwk9I
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g : E β†’ G C✝ : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G C : ℝβ‰₯0 hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C hs : Convex ℝ s ⊒ βˆ€ ⦃x : E⦄, x ∈ s β†’ βˆ€ ⦃y : E⦄, y ∈ s β†’ β€–f x - f yβ€– ≀ ↑C * β€–x - yβ€–
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le]
intro x x_in y y_in
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le]
Mathlib.Analysis.Calculus.MeanValue.476_0.ReDurB0qNQAwk9I
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g : E β†’ G C✝ : ℝ s : Set E x✝ y✝ : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G C : ℝβ‰₯0 hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C hs : Convex ℝ s x : E x_in : x ∈ s y : E y_in : y ∈ s ⊒ β€–f x - f yβ€– ≀ ↑C * β€–x - yβ€–
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in
exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in
Mathlib.Analysis.Calculus.MeanValue.476_0.ReDurB0qNQAwk9I
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f✝ g : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hs : Convex ℝ s f : E β†’ G hder : βˆ€αΆ  (y : E) in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y hcont : ContinuousWithinAt f' s x K : ℝβ‰₯0 hK : β€–f' xβ€–β‚Š < K ⊒ βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by
obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K }
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by
Mathlib.Analysis.Calculus.MeanValue.487_0.ReDurB0qNQAwk9I
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f✝ g : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hs : Convex ℝ s f : E β†’ G hder : βˆ€αΆ  (y : E) in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y hcont : ContinuousWithinAt f' s x K : ℝβ‰₯0 hK : β€–f' xβ€–β‚Š < K ⊒ βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† {y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K} case intro.intro E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f✝ g : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hs : Convex ℝ s f : E β†’ G hder : βˆ€αΆ  (y : E) in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y hcont : ContinuousWithinAt f' s x K : ℝβ‰₯0 hK : β€–f' xβ€–β‚Š < K Ξ΅ : ℝ Ξ΅0 : Ξ΅ > 0 hΞ΅ : ball x Ξ΅ ∩ s βŠ† {y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K} ⊒ βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K }
exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK))
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K }
Mathlib.Analysis.Calculus.MeanValue.487_0.ReDurB0qNQAwk9I
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t
Mathlib_Analysis_Calculus_MeanValue
case intro.intro E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f✝ g : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hs : Convex ℝ s f : E β†’ G hder : βˆ€αΆ  (y : E) in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y hcont : ContinuousWithinAt f' s x K : ℝβ‰₯0 hK : β€–f' xβ€–β‚Š < K Ξ΅ : ℝ Ξ΅0 : Ξ΅ > 0 hΞ΅ : ball x Ξ΅ ∩ s βŠ† {y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K} ⊒ βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK))
rw [inter_comm] at hΞ΅
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK))
Mathlib.Analysis.Calculus.MeanValue.487_0.ReDurB0qNQAwk9I
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t
Mathlib_Analysis_Calculus_MeanValue
case intro.intro E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f✝ g : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hs : Convex ℝ s f : E β†’ G hder : βˆ€αΆ  (y : E) in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y hcont : ContinuousWithinAt f' s x K : ℝβ‰₯0 hK : β€–f' xβ€–β‚Š < K Ξ΅ : ℝ Ξ΅0 : Ξ΅ > 0 hΞ΅ : s ∩ ball x Ξ΅ βŠ† {y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K} ⊒ βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅
refine' ⟨s ∩ ball x Ρ, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ρ0), _⟩
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅
Mathlib.Analysis.Calculus.MeanValue.487_0.ReDurB0qNQAwk9I
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t
Mathlib_Analysis_Calculus_MeanValue
case intro.intro E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f✝ g : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hs : Convex ℝ s f : E β†’ G hder : βˆ€αΆ  (y : E) in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y hcont : ContinuousWithinAt f' s x K : ℝβ‰₯0 hK : β€–f' xβ€–β‚Š < K Ξ΅ : ℝ Ξ΅0 : Ξ΅ > 0 hΞ΅ : s ∩ ball x Ξ΅ βŠ† {y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K} ⊒ LipschitzOnWith K f (s ∩ ball x Ξ΅)
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩
exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩
Mathlib.Analysis.Calculus.MeanValue.487_0.ReDurB0qNQAwk9I
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t
Mathlib_Analysis_Calculus_MeanValue
E✝ : Type u_1 inst✝⁹ : NormedAddCommGroup E✝ inst✝⁸ : NormedSpace ℝ E✝ F : Type u_2 inst✝⁷ : NormedAddCommGroup F inst✝⁢ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝⁡ : IsROrC π•œ inst✝⁴ : NormedSpace π•œ E✝ inst✝³ : NormedAddCommGroup G inst✝² : NormedSpace π•œ G f✝ g : E✝ β†’ G C✝ : ℝ s : Set E✝ x y : E✝ f' g' : E✝ β†’ E✝ β†’L[π•œ] G Ο† : E✝ β†’L[π•œ] G E : Type u_5 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace π•œ E f : E β†’ G C : ℝβ‰₯0 hf : Differentiable π•œ f bound : βˆ€ (x : E), β€–fderiv π•œ f xβ€–β‚Š ≀ C ⊒ LipschitzWith C f
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by
let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E
/-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by
Mathlib.Analysis.Calculus.MeanValue.553_0.ReDurB0qNQAwk9I
/-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f
Mathlib_Analysis_Calculus_MeanValue
E✝ : Type u_1 inst✝⁹ : NormedAddCommGroup E✝ inst✝⁸ : NormedSpace ℝ E✝ F : Type u_2 inst✝⁷ : NormedAddCommGroup F inst✝⁢ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝⁡ : IsROrC π•œ inst✝⁴ : NormedSpace π•œ E✝ inst✝³ : NormedAddCommGroup G inst✝² : NormedSpace π•œ G f✝ g : E✝ β†’ G C✝ : ℝ s : Set E✝ x y : E✝ f' g' : E✝ β†’ E✝ β†’L[π•œ] G Ο† : E✝ β†’L[π•œ] G E : Type u_5 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace π•œ E f : E β†’ G C : ℝβ‰₯0 hf : Differentiable π•œ f bound : βˆ€ (x : E), β€–fderiv π•œ f xβ€–β‚Š ≀ C A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E ⊒ LipschitzWith C f
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E
rw [← lipschitzOn_univ]
/-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E
Mathlib.Analysis.Calculus.MeanValue.553_0.ReDurB0qNQAwk9I
/-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f
Mathlib_Analysis_Calculus_MeanValue
E✝ : Type u_1 inst✝⁹ : NormedAddCommGroup E✝ inst✝⁸ : NormedSpace ℝ E✝ F : Type u_2 inst✝⁷ : NormedAddCommGroup F inst✝⁢ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝⁡ : IsROrC π•œ inst✝⁴ : NormedSpace π•œ E✝ inst✝³ : NormedAddCommGroup G inst✝² : NormedSpace π•œ G f✝ g : E✝ β†’ G C✝ : ℝ s : Set E✝ x y : E✝ f' g' : E✝ β†’ E✝ β†’L[π•œ] G Ο† : E✝ β†’L[π•œ] G E : Type u_5 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace π•œ E f : E β†’ G C : ℝβ‰₯0 hf : Differentiable π•œ f bound : βˆ€ (x : E), β€–fderiv π•œ f xβ€–β‚Š ≀ C A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E ⊒ LipschitzOnWith C f univ
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ]
exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ
/-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ]
Mathlib.Analysis.Calculus.MeanValue.553_0.ReDurB0qNQAwk9I
/-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C hs : Convex ℝ s xs : x ∈ s ys : y ∈ s ⊒ β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€–
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/
let g y := f y - Ο† y
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/
Mathlib.Analysis.Calculus.MeanValue.563_0.ReDurB0qNQAwk9I
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€–
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g✝ : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C hs : Convex ℝ s xs : x ∈ s ys : y ∈ s g : E β†’ G := fun y => f y - Ο† y ⊒ β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€–
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y
have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y
Mathlib.Analysis.Calculus.MeanValue.563_0.ReDurB0qNQAwk9I
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€–
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g✝ : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C hs : Convex ℝ s xs : x ∈ s ys : y ∈ s g : E β†’ G := fun y => f y - Ο† y hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x ⊒ β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€–
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt
calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt
Mathlib.Analysis.Calculus.MeanValue.563_0.ReDurB0qNQAwk9I
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€–
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g✝ : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C hs : Convex ℝ s xs : x ∈ s ys : y ∈ s g : E β†’ G := fun y => f y - Ο† y hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x ⊒ β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€–
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by
simp
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by
Mathlib.Analysis.Calculus.MeanValue.563_0.ReDurB0qNQAwk9I
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€–
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g✝ : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C hs : Convex ℝ s xs : x ∈ s ys : y ∈ s g : E β†’ G := fun y => f y - Ο† y hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x ⊒ β€–f y - f x - (Ο† y - Ο† x)β€– = β€–f y - Ο† y - (f x - Ο† x)β€–
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by
congr 1
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by
Mathlib.Analysis.Calculus.MeanValue.563_0.ReDurB0qNQAwk9I
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€–
Mathlib_Analysis_Calculus_MeanValue
case e_a E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g✝ : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C hs : Convex ℝ s xs : x ∈ s ys : y ∈ s g : E β†’ G := fun y => f y - Ο† y hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x ⊒ f y - f x - (Ο† y - Ο† x) = f y - Ο† y - (f x - Ο† x)
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1;
abel
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1;
Mathlib.Analysis.Calculus.MeanValue.563_0.ReDurB0qNQAwk9I
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€–
Mathlib_Analysis_Calculus_MeanValue
case e_a E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g✝ : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C hs : Convex ℝ s xs : x ∈ s ys : y ∈ s g : E β†’ G := fun y => f y - Ο† y hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x ⊒ f y - f x - (Ο† y - Ο† x) = f y - Ο† y - (f x - Ο† x)
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1;
abel
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1;
Mathlib.Analysis.Calculus.MeanValue.563_0.ReDurB0qNQAwk9I
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€–
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g✝ : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C hs : Convex ℝ s xs : x ∈ s ys : y ∈ s g : E β†’ G := fun y => f y - Ο† y hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x ⊒ β€–f y - Ο† y - (f x - Ο† x)β€– = β€–g y - g xβ€–
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by
simp
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by
Mathlib.Analysis.Calculus.MeanValue.563_0.ReDurB0qNQAwk9I
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€–
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hs : Convex ℝ s hf : DifferentiableOn π•œ f s hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0 hx : x ∈ s hy : y ∈ s ⊒ f x = f y
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by
have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl]
/-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by
Mathlib.Analysis.Calculus.MeanValue.598_0.ReDurB0qNQAwk9I
/-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g : E β†’ G C : ℝ s : Set E x✝ y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hs : Convex ℝ s hf : DifferentiableOn π•œ f s hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0 hx✝ : x✝ ∈ s hy : y ∈ s x : E hx : x ∈ s ⊒ β€–fderivWithin π•œ f s xβ€– ≀ 0
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by
simp only [hf' x hx, norm_zero, le_rfl]
/-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by
Mathlib.Analysis.Calculus.MeanValue.598_0.ReDurB0qNQAwk9I
/-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g : E β†’ G C : ℝ s : Set E x y : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hs : Convex ℝ s hf : DifferentiableOn π•œ f s hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0 hx : x ∈ s hy : y ∈ s bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 ⊒ f x = f y
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl]
simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy
/-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl]
Mathlib.Analysis.Calculus.MeanValue.598_0.ReDurB0qNQAwk9I
/-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y
Mathlib_Analysis_Calculus_MeanValue
E✝ : Type u_1 inst✝⁹ : NormedAddCommGroup E✝ inst✝⁸ : NormedSpace ℝ E✝ F : Type u_2 inst✝⁷ : NormedAddCommGroup F inst✝⁢ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝⁡ : IsROrC π•œ inst✝⁴ : NormedSpace π•œ E✝ inst✝³ : NormedAddCommGroup G inst✝² : NormedSpace π•œ G f✝ g : E✝ β†’ G C : ℝ s : Set E✝ x✝ y✝ : E✝ f' g' : E✝ β†’ E✝ β†’L[π•œ] G Ο† : E✝ β†’L[π•œ] G E : Type u_5 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace π•œ E f : E β†’ G hf : Differentiable π•œ f hf' : βˆ€ (x : E), fderiv π•œ f x = 0 x y : E ⊒ f x = f y
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by
let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E
theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by
Mathlib.Analysis.Calculus.MeanValue.608_0.ReDurB0qNQAwk9I
theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y
Mathlib_Analysis_Calculus_MeanValue
E✝ : Type u_1 inst✝⁹ : NormedAddCommGroup E✝ inst✝⁸ : NormedSpace ℝ E✝ F : Type u_2 inst✝⁷ : NormedAddCommGroup F inst✝⁢ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝⁡ : IsROrC π•œ inst✝⁴ : NormedSpace π•œ E✝ inst✝³ : NormedAddCommGroup G inst✝² : NormedSpace π•œ G f✝ g : E✝ β†’ G C : ℝ s : Set E✝ x✝ y✝ : E✝ f' g' : E✝ β†’ E✝ β†’L[π•œ] G Ο† : E✝ β†’L[π•œ] G E : Type u_5 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace π•œ E f : E β†’ G hf : Differentiable π•œ f hf' : βˆ€ (x : E), fderiv π•œ f x = 0 x y : E A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E ⊒ f x = f y
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E
exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial
theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E
Mathlib.Analysis.Calculus.MeanValue.608_0.ReDurB0qNQAwk9I
theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y
Mathlib_Analysis_Calculus_MeanValue
E✝ : Type u_1 inst✝⁹ : NormedAddCommGroup E✝ inst✝⁸ : NormedSpace ℝ E✝ F : Type u_2 inst✝⁷ : NormedAddCommGroup F inst✝⁢ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝⁡ : IsROrC π•œ inst✝⁴ : NormedSpace π•œ E✝ inst✝³ : NormedAddCommGroup G inst✝² : NormedSpace π•œ G f✝ g : E✝ β†’ G C : ℝ s : Set E✝ x✝² y✝ : E✝ f' g' : E✝ β†’ E✝ β†’L[π•œ] G Ο† : E✝ β†’L[π•œ] G E : Type u_5 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace π•œ E f : E β†’ G hf : Differentiable π•œ f hf' : βˆ€ (x : E), fderiv π•œ f x = 0 x✝¹ y : E A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E x : E x✝ : x ∈ univ ⊒ fderivWithin π•œ f univ x = 0
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by
rw [fderivWithin_univ]
theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by
Mathlib.Analysis.Calculus.MeanValue.608_0.ReDurB0qNQAwk9I
theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y
Mathlib_Analysis_Calculus_MeanValue
E✝ : Type u_1 inst✝⁹ : NormedAddCommGroup E✝ inst✝⁸ : NormedSpace ℝ E✝ F : Type u_2 inst✝⁷ : NormedAddCommGroup F inst✝⁢ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝⁡ : IsROrC π•œ inst✝⁴ : NormedSpace π•œ E✝ inst✝³ : NormedAddCommGroup G inst✝² : NormedSpace π•œ G f✝ g : E✝ β†’ G C : ℝ s : Set E✝ x✝² y✝ : E✝ f' g' : E✝ β†’ E✝ β†’L[π•œ] G Ο† : E✝ β†’L[π•œ] G E : Type u_5 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace π•œ E f : E β†’ G hf : Differentiable π•œ f hf' : βˆ€ (x : E), fderiv π•œ f x = 0 x✝¹ y : E A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E x : E x✝ : x ∈ univ ⊒ fderiv π•œ f x = 0
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ];
exact hf' x
theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ];
Mathlib.Analysis.Calculus.MeanValue.608_0.ReDurB0qNQAwk9I
theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g : E β†’ G C : ℝ s : Set E x y✝ : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hs : Convex ℝ s hf : DifferentiableOn π•œ f s hg : DifferentiableOn π•œ g s hs' : UniqueDiffOn π•œ s hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x hx : x ∈ s hfgx : f x = g x y : E hy : y ∈ s ⊒ f y = g y
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by
suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this
/-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by
Mathlib.Analysis.Calculus.MeanValue.617_0.ReDurB0qNQAwk9I
/-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g : E β†’ G C : ℝ s : Set E x y✝ : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hs : Convex ℝ s hf : DifferentiableOn π•œ f s hg : DifferentiableOn π•œ g s hs' : UniqueDiffOn π•œ s hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x hx : x ∈ s hfgx : f x = g x y : E hy : y ∈ s this : f x - g x = f y - g y ⊒ f y = g y
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by
rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this
/-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by
Mathlib.Analysis.Calculus.MeanValue.617_0.ReDurB0qNQAwk9I
/-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g : E β†’ G C : ℝ s : Set E x y✝ : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hs : Convex ℝ s hf : DifferentiableOn π•œ f s hg : DifferentiableOn π•œ g s hs' : UniqueDiffOn π•œ s hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x hx : x ∈ s hfgx : f x = g x y : E hy : y ∈ s ⊒ f x - g x = f y - g y
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this
refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy
/-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this
Mathlib.Analysis.Calculus.MeanValue.617_0.ReDurB0qNQAwk9I
/-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f g : E β†’ G C : ℝ s : Set E x y✝ : E f' g' : E β†’ E β†’L[π•œ] G Ο† : E β†’L[π•œ] G hs : Convex ℝ s hf : DifferentiableOn π•œ f s hg : DifferentiableOn π•œ g s hs' : UniqueDiffOn π•œ s hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x hx : x ∈ s hfgx : f x = g x y : E hy : y ∈ s z : E hz : z ∈ s ⊒ fderivWithin π•œ (fun y => f y - g y) s z = 0
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy
rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz]
/-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy
Mathlib.Analysis.Calculus.MeanValue.617_0.ReDurB0qNQAwk9I
/-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g
Mathlib_Analysis_Calculus_MeanValue
E✝ : Type u_1 inst✝⁹ : NormedAddCommGroup E✝ inst✝⁸ : NormedSpace ℝ E✝ F : Type u_2 inst✝⁷ : NormedAddCommGroup F inst✝⁢ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝⁡ : IsROrC π•œ inst✝⁴ : NormedSpace π•œ E✝ inst✝³ : NormedAddCommGroup G inst✝² : NormedSpace π•œ G f✝ g✝ : E✝ β†’ G C : ℝ s : Set E✝ x✝ y : E✝ f' g' : E✝ β†’ E✝ β†’L[π•œ] G Ο† : E✝ β†’L[π•œ] G E : Type u_5 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace π•œ E f g : E β†’ G hf : Differentiable π•œ f hg : Differentiable π•œ g hf' : βˆ€ (x : E), fderiv π•œ f x = fderiv π•œ g x x : E hfgx : f x = g x ⊒ f = g
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by
let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E
theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by
Mathlib.Analysis.Calculus.MeanValue.628_0.ReDurB0qNQAwk9I
theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g
Mathlib_Analysis_Calculus_MeanValue
E✝ : Type u_1 inst✝⁹ : NormedAddCommGroup E✝ inst✝⁸ : NormedSpace ℝ E✝ F : Type u_2 inst✝⁷ : NormedAddCommGroup F inst✝⁢ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝⁡ : IsROrC π•œ inst✝⁴ : NormedSpace π•œ E✝ inst✝³ : NormedAddCommGroup G inst✝² : NormedSpace π•œ G f✝ g✝ : E✝ β†’ G C : ℝ s : Set E✝ x✝ y : E✝ f' g' : E✝ β†’ E✝ β†’L[π•œ] G Ο† : E✝ β†’L[π•œ] G E : Type u_5 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace π•œ E f g : E β†’ G hf : Differentiable π•œ f hg : Differentiable π•œ g hf' : βˆ€ (x : E), fderiv π•œ f x = fderiv π•œ g x x : E hfgx : f x = g x A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E ⊒ f = g
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E
suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x
theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E
Mathlib.Analysis.Calculus.MeanValue.628_0.ReDurB0qNQAwk9I
theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g
Mathlib_Analysis_Calculus_MeanValue
E✝ : Type u_1 inst✝⁹ : NormedAddCommGroup E✝ inst✝⁸ : NormedSpace ℝ E✝ F : Type u_2 inst✝⁷ : NormedAddCommGroup F inst✝⁢ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝⁡ : IsROrC π•œ inst✝⁴ : NormedSpace π•œ E✝ inst✝³ : NormedAddCommGroup G inst✝² : NormedSpace π•œ G f✝ g✝ : E✝ β†’ G C : ℝ s : Set E✝ x✝ y : E✝ f' g' : E✝ β†’ E✝ β†’L[π•œ] G Ο† : E✝ β†’L[π•œ] G E : Type u_5 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace π•œ E f g : E β†’ G hf : Differentiable π•œ f hg : Differentiable π•œ g hf' : βˆ€ (x : E), fderiv π•œ f x = fderiv π•œ g x x : E hfgx : f x = g x A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E ⊒ EqOn f g univ
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x
exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx
theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x
Mathlib.Analysis.Calculus.MeanValue.628_0.ReDurB0qNQAwk9I
theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g
Mathlib_Analysis_Calculus_MeanValue
E✝ : Type u_1 inst✝⁹ : NormedAddCommGroup E✝ inst✝⁸ : NormedSpace ℝ E✝ F : Type u_2 inst✝⁷ : NormedAddCommGroup F inst✝⁢ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝⁡ : IsROrC π•œ inst✝⁴ : NormedSpace π•œ E✝ inst✝³ : NormedAddCommGroup G inst✝² : NormedSpace π•œ G f✝ g✝ : E✝ β†’ G C : ℝ s : Set E✝ x✝² y : E✝ f' g' : E✝ β†’ E✝ β†’L[π•œ] G Ο† : E✝ β†’L[π•œ] G E : Type u_5 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace π•œ E f g : E β†’ G hf : Differentiable π•œ f hg : Differentiable π•œ g hf' : βˆ€ (x : E), fderiv π•œ f x = fderiv π•œ g x x✝¹ : E hfgx : f x✝¹ = g x✝¹ A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E x : E x✝ : x ∈ univ ⊒ fderivWithin π•œ f univ x = fderivWithin π•œ g univ x
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by
simpa using hf' _
theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by
Mathlib.Analysis.Calculus.MeanValue.628_0.ReDurB0qNQAwk9I
theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f f' : π•œ β†’ G s : Set π•œ x✝ y : π•œ C : ℝ hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C hs : Convex ℝ s xs : x✝ ∈ s ys : y ∈ s x : π•œ hx : x ∈ s ⊒ β€–smulRight 1 (f' x)β€– ≀ β€–f' xβ€–
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by
simp
/-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by
Mathlib.Analysis.Calculus.MeanValue.644_0.ReDurB0qNQAwk9I
/-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€–
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f f' : π•œ β†’ G s : Set π•œ x✝ y : π•œ C : ℝβ‰₯0 hs : Convex ℝ s hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C x : π•œ hx : x ∈ s ⊒ β€–smulRight 1 (f' x)β€–β‚Š ≀ β€–f' xβ€–β‚Š
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by
simp
/-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by
Mathlib.Analysis.Calculus.MeanValue.653_0.ReDurB0qNQAwk9I
/-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f f' : π•œ β†’ G s : Set π•œ x✝ y✝ : π•œ hf : Differentiable π•œ f hf' : βˆ€ (x : π•œ), deriv f x = 0 x y z : π•œ ⊒ fderiv π•œ f z = 0
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by
ext
/-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by
Mathlib.Analysis.Calculus.MeanValue.707_0.ReDurB0qNQAwk9I
/-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y
Mathlib_Analysis_Calculus_MeanValue
case h E : Type u_1 inst✝⁷ : NormedAddCommGroup E inst✝⁢ : NormedSpace ℝ E F : Type u_2 inst✝⁡ : NormedAddCommGroup F inst✝⁴ : NormedSpace ℝ F π•œ : Type u_3 G : Type u_4 inst✝³ : IsROrC π•œ inst✝² : NormedSpace π•œ E inst✝¹ : NormedAddCommGroup G inst✝ : NormedSpace π•œ G f f' : π•œ β†’ G s : Set π•œ x✝ y✝ : π•œ hf : Differentiable π•œ f hf' : βˆ€ (x : π•œ), deriv f x = 0 x y z : π•œ ⊒ (fderiv π•œ f z) 1 = 0 1
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext;
simp [← deriv_fderiv, hf']
/-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext;
Mathlib.Analysis.Calculus.MeanValue.707_0.ReDurB0qNQAwk9I
/-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) ⊒ βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by
let h x := (g b - g a) * f x - (f b - f a) * g x
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by
Mathlib.Analysis.Calculus.MeanValue.728_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) h : ℝ β†’ ℝ := fun x => (g b - g a) * f x - (f b - f a) * g x ⊒ βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x
have hI : h a = h b := by simp only; ring
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x
Mathlib.Analysis.Calculus.MeanValue.728_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) h : ℝ β†’ ℝ := fun x => (g b - g a) * f x - (f b - f a) * g x ⊒ h a = h b
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by
simp only
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by
Mathlib.Analysis.Calculus.MeanValue.728_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) h : ℝ β†’ ℝ := fun x => (g b - g a) * f x - (f b - f a) * g x ⊒ (g b - g a) * f a - (f b - f a) * g a = (g b - g a) * f b - (f b - f a) * g b
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only;
ring
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only;
Mathlib.Analysis.Calculus.MeanValue.728_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) h : ℝ β†’ ℝ := fun x => (g b - g a) * f x - (f b - f a) * g x hI : h a = h b ⊒ βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring
let h' x := (g b - g a) * f' x - (f b - f a) * g' x
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring
Mathlib.Analysis.Calculus.MeanValue.728_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) h : ℝ β†’ ℝ := fun x => (g b - g a) * f x - (f b - f a) * g x hI : h a = h b h' : ℝ β†’ ℝ := fun x => (g b - g a) * f' x - (f b - f a) * g' x ⊒ βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x
have hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a))
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x
Mathlib.Analysis.Calculus.MeanValue.728_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) h : ℝ β†’ ℝ := fun x => (g b - g a) * f x - (f b - f a) * g x hI : h a = h b h' : ℝ β†’ ℝ := fun x => (g b - g a) * f' x - (f b - f a) * g' x hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x ⊒ βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x have hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a))
have hhc : ContinuousOn h (Icc a b) := (continuousOn_const.mul hfc).sub (continuousOn_const.mul hgc)
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x have hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a))
Mathlib.Analysis.Calculus.MeanValue.728_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) h : ℝ β†’ ℝ := fun x => (g b - g a) * f x - (f b - f a) * g x hI : h a = h b h' : ℝ β†’ ℝ := fun x => (g b - g a) * f' x - (f b - f a) * g' x hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x hhc : ContinuousOn h (Icc a b) ⊒ βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x have hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a)) have hhc : ContinuousOn h (Icc a b) := (continuousOn_const.mul hfc).sub (continuousOn_const.mul hgc)
rcases exists_hasDerivAt_eq_zero hab hhc hI hhh' with ⟨c, cmem, hc⟩
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x have hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a)) have hhc : ContinuousOn h (Icc a b) := (continuousOn_const.mul hfc).sub (continuousOn_const.mul hgc)
Mathlib.Analysis.Calculus.MeanValue.728_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c
Mathlib_Analysis_Calculus_MeanValue
case intro.intro E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) h : ℝ β†’ ℝ := fun x => (g b - g a) * f x - (f b - f a) * g x hI : h a = h b h' : ℝ β†’ ℝ := fun x => (g b - g a) * f' x - (f b - f a) * g' x hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x hhc : ContinuousOn h (Icc a b) c : ℝ cmem : c ∈ Ioo a b hc : h' c = 0 ⊒ βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x have hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a)) have hhc : ContinuousOn h (Icc a b) := (continuousOn_const.mul hfc).sub (continuousOn_const.mul hgc) rcases exists_hasDerivAt_eq_zero hab hhc hI hhh' with ⟨c, cmem, hc⟩
exact ⟨c, cmem, sub_eq_zero.1 hc⟩
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x have hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a)) have hhc : ContinuousOn h (Icc a b) := (continuousOn_const.mul hfc).sub (continuousOn_const.mul hgc) rcases exists_hasDerivAt_eq_zero hab hhc hI hhh' with ⟨c, cmem, hc⟩
Mathlib.Analysis.Calculus.MeanValue.728_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) lfa lga lfb lgb : ℝ hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hfa : Tendsto f (𝓝[>] a) (𝓝 lfa) hga : Tendsto g (𝓝[>] a) (𝓝 lga) hfb : Tendsto f (𝓝[<] b) (𝓝 lfb) hgb : Tendsto g (𝓝[<] b) (𝓝 lgb) ⊒ βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x have hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a)) have hhc : ContinuousOn h (Icc a b) := (continuousOn_const.mul hfc).sub (continuousOn_const.mul hgc) rcases exists_hasDerivAt_eq_zero hab hhc hI hhh' with ⟨c, cmem, hc⟩ exact ⟨c, cmem, sub_eq_zero.1 hc⟩ #align exists_ratio_has_deriv_at_eq_ratio_slope exists_ratio_hasDerivAt_eq_ratio_slope /-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by
let h x := (lgb - lga) * f x - (lfb - lfa) * g x
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by
Mathlib.Analysis.Calculus.MeanValue.742_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) lfa lga lfb lgb : ℝ hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hfa : Tendsto f (𝓝[>] a) (𝓝 lfa) hga : Tendsto g (𝓝[>] a) (𝓝 lga) hfb : Tendsto f (𝓝[<] b) (𝓝 lfb) hgb : Tendsto g (𝓝[<] b) (𝓝 lgb) h : ℝ β†’ ℝ := fun x => (lgb - lga) * f x - (lfb - lfa) * g x ⊒ βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x have hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a)) have hhc : ContinuousOn h (Icc a b) := (continuousOn_const.mul hfc).sub (continuousOn_const.mul hgc) rcases exists_hasDerivAt_eq_zero hab hhc hI hhh' with ⟨c, cmem, hc⟩ exact ⟨c, cmem, sub_eq_zero.1 hc⟩ #align exists_ratio_has_deriv_at_eq_ratio_slope exists_ratio_hasDerivAt_eq_ratio_slope /-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x
have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[>] a) (𝓝 <| (lgb - lga) * lfa - (lfb - lfa) * lga) := (tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga) convert this using 2 ring
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x
Mathlib.Analysis.Calculus.MeanValue.742_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) lfa lga lfb lgb : ℝ hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hfa : Tendsto f (𝓝[>] a) (𝓝 lfa) hga : Tendsto g (𝓝[>] a) (𝓝 lga) hfb : Tendsto f (𝓝[<] b) (𝓝 lfb) hgb : Tendsto g (𝓝[<] b) (𝓝 lgb) h : ℝ β†’ ℝ := fun x => (lgb - lga) * f x - (lfb - lfa) * g x ⊒ Tendsto h (𝓝[>] a) (𝓝 (lgb * lfa - lfb * lga))
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x have hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a)) have hhc : ContinuousOn h (Icc a b) := (continuousOn_const.mul hfc).sub (continuousOn_const.mul hgc) rcases exists_hasDerivAt_eq_zero hab hhc hI hhh' with ⟨c, cmem, hc⟩ exact ⟨c, cmem, sub_eq_zero.1 hc⟩ #align exists_ratio_has_deriv_at_eq_ratio_slope exists_ratio_hasDerivAt_eq_ratio_slope /-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by
have : Tendsto h (𝓝[>] a) (𝓝 <| (lgb - lga) * lfa - (lfb - lfa) * lga) := (tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga)
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by
Mathlib.Analysis.Calculus.MeanValue.742_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) lfa lga lfb lgb : ℝ hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hfa : Tendsto f (𝓝[>] a) (𝓝 lfa) hga : Tendsto g (𝓝[>] a) (𝓝 lga) hfb : Tendsto f (𝓝[<] b) (𝓝 lfb) hgb : Tendsto g (𝓝[<] b) (𝓝 lgb) h : ℝ β†’ ℝ := fun x => (lgb - lga) * f x - (lfb - lfa) * g x this : Tendsto h (𝓝[>] a) (𝓝 ((lgb - lga) * lfa - (lfb - lfa) * lga)) ⊒ Tendsto h (𝓝[>] a) (𝓝 (lgb * lfa - lfb * lga))
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x have hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a)) have hhc : ContinuousOn h (Icc a b) := (continuousOn_const.mul hfc).sub (continuousOn_const.mul hgc) rcases exists_hasDerivAt_eq_zero hab hhc hI hhh' with ⟨c, cmem, hc⟩ exact ⟨c, cmem, sub_eq_zero.1 hc⟩ #align exists_ratio_has_deriv_at_eq_ratio_slope exists_ratio_hasDerivAt_eq_ratio_slope /-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[>] a) (𝓝 <| (lgb - lga) * lfa - (lfb - lfa) * lga) := (tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga)
convert this using 2
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[>] a) (𝓝 <| (lgb - lga) * lfa - (lfb - lfa) * lga) := (tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga)
Mathlib.Analysis.Calculus.MeanValue.742_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c
Mathlib_Analysis_Calculus_MeanValue
case h.e'_5.h.e'_3 E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) lfa lga lfb lgb : ℝ hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hfa : Tendsto f (𝓝[>] a) (𝓝 lfa) hga : Tendsto g (𝓝[>] a) (𝓝 lga) hfb : Tendsto f (𝓝[<] b) (𝓝 lfb) hgb : Tendsto g (𝓝[<] b) (𝓝 lgb) h : ℝ β†’ ℝ := fun x => (lgb - lga) * f x - (lfb - lfa) * g x this : Tendsto h (𝓝[>] a) (𝓝 ((lgb - lga) * lfa - (lfb - lfa) * lga)) ⊒ lgb * lfa - lfb * lga = (lgb - lga) * lfa - (lfb - lfa) * lga
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x have hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a)) have hhc : ContinuousOn h (Icc a b) := (continuousOn_const.mul hfc).sub (continuousOn_const.mul hgc) rcases exists_hasDerivAt_eq_zero hab hhc hI hhh' with ⟨c, cmem, hc⟩ exact ⟨c, cmem, sub_eq_zero.1 hc⟩ #align exists_ratio_has_deriv_at_eq_ratio_slope exists_ratio_hasDerivAt_eq_ratio_slope /-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[>] a) (𝓝 <| (lgb - lga) * lfa - (lfb - lfa) * lga) := (tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga) convert this using 2
ring
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[>] a) (𝓝 <| (lgb - lga) * lfa - (lfb - lfa) * lga) := (tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga) convert this using 2
Mathlib.Analysis.Calculus.MeanValue.742_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) lfa lga lfb lgb : ℝ hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hfa : Tendsto f (𝓝[>] a) (𝓝 lfa) hga : Tendsto g (𝓝[>] a) (𝓝 lga) hfb : Tendsto f (𝓝[<] b) (𝓝 lfb) hgb : Tendsto g (𝓝[<] b) (𝓝 lgb) h : ℝ β†’ ℝ := fun x => (lgb - lga) * f x - (lfb - lfa) * g x hha : Tendsto h (𝓝[>] a) (𝓝 (lgb * lfa - lfb * lga)) ⊒ βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x have hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a)) have hhc : ContinuousOn h (Icc a b) := (continuousOn_const.mul hfc).sub (continuousOn_const.mul hgc) rcases exists_hasDerivAt_eq_zero hab hhc hI hhh' with ⟨c, cmem, hc⟩ exact ⟨c, cmem, sub_eq_zero.1 hc⟩ #align exists_ratio_has_deriv_at_eq_ratio_slope exists_ratio_hasDerivAt_eq_ratio_slope /-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[>] a) (𝓝 <| (lgb - lga) * lfa - (lfb - lfa) * lga) := (tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga) convert this using 2 ring
have hhb : Tendsto h (𝓝[<] b) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[<] b) (𝓝 <| (lgb - lga) * lfb - (lfb - lfa) * lgb) := (tendsto_const_nhds.mul hfb).sub (tendsto_const_nhds.mul hgb) convert this using 2 ring
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[>] a) (𝓝 <| (lgb - lga) * lfa - (lfb - lfa) * lga) := (tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga) convert this using 2 ring
Mathlib.Analysis.Calculus.MeanValue.742_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) lfa lga lfb lgb : ℝ hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hfa : Tendsto f (𝓝[>] a) (𝓝 lfa) hga : Tendsto g (𝓝[>] a) (𝓝 lga) hfb : Tendsto f (𝓝[<] b) (𝓝 lfb) hgb : Tendsto g (𝓝[<] b) (𝓝 lgb) h : ℝ β†’ ℝ := fun x => (lgb - lga) * f x - (lfb - lfa) * g x hha : Tendsto h (𝓝[>] a) (𝓝 (lgb * lfa - lfb * lga)) ⊒ Tendsto h (𝓝[<] b) (𝓝 (lgb * lfa - lfb * lga))
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x have hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a)) have hhc : ContinuousOn h (Icc a b) := (continuousOn_const.mul hfc).sub (continuousOn_const.mul hgc) rcases exists_hasDerivAt_eq_zero hab hhc hI hhh' with ⟨c, cmem, hc⟩ exact ⟨c, cmem, sub_eq_zero.1 hc⟩ #align exists_ratio_has_deriv_at_eq_ratio_slope exists_ratio_hasDerivAt_eq_ratio_slope /-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[>] a) (𝓝 <| (lgb - lga) * lfa - (lfb - lfa) * lga) := (tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga) convert this using 2 ring have hhb : Tendsto h (𝓝[<] b) (𝓝 <| lgb * lfa - lfb * lga) := by
have : Tendsto h (𝓝[<] b) (𝓝 <| (lgb - lga) * lfb - (lfb - lfa) * lgb) := (tendsto_const_nhds.mul hfb).sub (tendsto_const_nhds.mul hgb)
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[>] a) (𝓝 <| (lgb - lga) * lfa - (lfb - lfa) * lga) := (tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga) convert this using 2 ring have hhb : Tendsto h (𝓝[<] b) (𝓝 <| lgb * lfa - lfb * lga) := by
Mathlib.Analysis.Calculus.MeanValue.742_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) lfa lga lfb lgb : ℝ hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hfa : Tendsto f (𝓝[>] a) (𝓝 lfa) hga : Tendsto g (𝓝[>] a) (𝓝 lga) hfb : Tendsto f (𝓝[<] b) (𝓝 lfb) hgb : Tendsto g (𝓝[<] b) (𝓝 lgb) h : ℝ β†’ ℝ := fun x => (lgb - lga) * f x - (lfb - lfa) * g x hha : Tendsto h (𝓝[>] a) (𝓝 (lgb * lfa - lfb * lga)) this : Tendsto h (𝓝[<] b) (𝓝 ((lgb - lga) * lfb - (lfb - lfa) * lgb)) ⊒ Tendsto h (𝓝[<] b) (𝓝 (lgb * lfa - lfb * lga))
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x have hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a)) have hhc : ContinuousOn h (Icc a b) := (continuousOn_const.mul hfc).sub (continuousOn_const.mul hgc) rcases exists_hasDerivAt_eq_zero hab hhc hI hhh' with ⟨c, cmem, hc⟩ exact ⟨c, cmem, sub_eq_zero.1 hc⟩ #align exists_ratio_has_deriv_at_eq_ratio_slope exists_ratio_hasDerivAt_eq_ratio_slope /-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[>] a) (𝓝 <| (lgb - lga) * lfa - (lfb - lfa) * lga) := (tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga) convert this using 2 ring have hhb : Tendsto h (𝓝[<] b) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[<] b) (𝓝 <| (lgb - lga) * lfb - (lfb - lfa) * lgb) := (tendsto_const_nhds.mul hfb).sub (tendsto_const_nhds.mul hgb)
convert this using 2
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[>] a) (𝓝 <| (lgb - lga) * lfa - (lfb - lfa) * lga) := (tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga) convert this using 2 ring have hhb : Tendsto h (𝓝[<] b) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[<] b) (𝓝 <| (lgb - lga) * lfb - (lfb - lfa) * lgb) := (tendsto_const_nhds.mul hfb).sub (tendsto_const_nhds.mul hgb)
Mathlib.Analysis.Calculus.MeanValue.742_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c
Mathlib_Analysis_Calculus_MeanValue
case h.e'_5.h.e'_3 E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) lfa lga lfb lgb : ℝ hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hfa : Tendsto f (𝓝[>] a) (𝓝 lfa) hga : Tendsto g (𝓝[>] a) (𝓝 lga) hfb : Tendsto f (𝓝[<] b) (𝓝 lfb) hgb : Tendsto g (𝓝[<] b) (𝓝 lgb) h : ℝ β†’ ℝ := fun x => (lgb - lga) * f x - (lfb - lfa) * g x hha : Tendsto h (𝓝[>] a) (𝓝 (lgb * lfa - lfb * lga)) this : Tendsto h (𝓝[<] b) (𝓝 ((lgb - lga) * lfb - (lfb - lfa) * lgb)) ⊒ lgb * lfa - lfb * lga = (lgb - lga) * lfb - (lfb - lfa) * lgb
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x have hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a)) have hhc : ContinuousOn h (Icc a b) := (continuousOn_const.mul hfc).sub (continuousOn_const.mul hgc) rcases exists_hasDerivAt_eq_zero hab hhc hI hhh' with ⟨c, cmem, hc⟩ exact ⟨c, cmem, sub_eq_zero.1 hc⟩ #align exists_ratio_has_deriv_at_eq_ratio_slope exists_ratio_hasDerivAt_eq_ratio_slope /-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[>] a) (𝓝 <| (lgb - lga) * lfa - (lfb - lfa) * lga) := (tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga) convert this using 2 ring have hhb : Tendsto h (𝓝[<] b) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[<] b) (𝓝 <| (lgb - lga) * lfb - (lfb - lfa) * lgb) := (tendsto_const_nhds.mul hfb).sub (tendsto_const_nhds.mul hgb) convert this using 2
ring
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[>] a) (𝓝 <| (lgb - lga) * lfa - (lfb - lfa) * lga) := (tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga) convert this using 2 ring have hhb : Tendsto h (𝓝[<] b) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[<] b) (𝓝 <| (lgb - lga) * lfb - (lfb - lfa) * lgb) := (tendsto_const_nhds.mul hfb).sub (tendsto_const_nhds.mul hgb) convert this using 2
Mathlib.Analysis.Calculus.MeanValue.742_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c
Mathlib_Analysis_Calculus_MeanValue
E : Type u_1 inst✝³ : NormedAddCommGroup E inst✝² : NormedSpace ℝ E F : Type u_2 inst✝¹ : NormedAddCommGroup F inst✝ : NormedSpace ℝ F f f' : ℝ β†’ ℝ a b : ℝ hab : a < b hfc : ContinuousOn f (Icc a b) hff'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hfd : DifferentiableOn ℝ f (Ioo a b) g g' : ℝ β†’ ℝ hgc : ContinuousOn g (Icc a b) hgg'✝ : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hgd : DifferentiableOn ℝ g (Ioo a b) lfa lga lfb lgb : ℝ hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x hfa : Tendsto f (𝓝[>] a) (𝓝 lfa) hga : Tendsto g (𝓝[>] a) (𝓝 lga) hfb : Tendsto f (𝓝[<] b) (𝓝 lfb) hgb : Tendsto g (𝓝[<] b) (𝓝 lgb) h : ℝ β†’ ℝ := fun x => (lgb - lga) * f x - (lfb - lfa) * g x hha : Tendsto h (𝓝[>] a) (𝓝 (lgb * lfa - lfb * lga)) hhb : Tendsto h (𝓝[<] b) (𝓝 (lgb * lfa - lfb * lga)) ⊒ βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Convex.Normed import Mathlib.Data.IsROrC.Basic import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `IsROrC`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `βˆ€ x, C (</≀/>/β‰₯) (f' x)`, then `C * (y - x) (</≀/>/β‰₯) (f y - f x)` whenever `x < y`. * `Convex.monotoneOn_of_deriv_nonneg`, `Convex.antitoneOn_of_deriv_nonpos`, `Convex.strictMono_of_deriv_pos`, `Convex.strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine' nonempty_of_mem (inter_mem _ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y exact (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine' ⟨z, _, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => _) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine' norm_image_sub_le_of_norm_deriv_le_segment' _ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi #align eq_of_deriv_within_eq eq_of_derivWithin_eq end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[IsROrC π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {π•œ G : Type*} [IsROrC π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace Convex variable {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_op_norm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in #align convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } exact mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine' ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), _⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono (inter_subset_left _ _)) fun y hy => (hΞ΅ hy).2.le #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont #align convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le Convex.norm_image_sub_le_of_norm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_within_le Convex.lipschitzOnWith_of_nnnorm_fderivWithin_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le Convex.norm_image_sub_le_of_norm_fderiv_le /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_fderiv_le Convex.lipschitzOnWith_of_nnnorm_fderiv_le /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOn_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys #align convex.norm_image_sub_le_of_norm_has_fderiv_within_le' Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_within_le' Convex.norm_image_sub_le_of_norm_fderivWithin_le' /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_fderiv_le' Convex.norm_image_sub_le_of_norm_fderiv_le' /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy #align convex.is_const_of_fderiv_within_eq_zero Convex.is_const_of_fderivWithin_eq_zero theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial #align is_const_of_fderiv_eq_zero is_const_of_fderiv_eq_zero /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = fderivWithin π•œ g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine' hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => _) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] #align convex.eq_on_of_fderiv_within_eq Convex.eqOn_of_fderivWithin_eq theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx #align eq_of_fderiv_eq eq_of_fderiv_eq end Convex namespace Convex variable {f f' : π•œ β†’ G} {s : Set π•œ} {x y : π•œ} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys #align convex.norm_image_sub_le_of_norm_has_deriv_within_le Convex.norm_image_sub_le_of_norm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : βˆ€ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs #align convex.lipschitz_on_with_of_nnnorm_has_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_hasDerivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_within_le Convex.norm_image_sub_le_of_norm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝβ‰₯0} (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–derivWithin f s xβ€–β‚Š ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_within_le Convex.lipschitzOnWith_of_nnnorm_derivWithin_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys #align convex.norm_image_sub_le_of_norm_deriv_le Convex.norm_image_sub_le_of_norm_deriv_le /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–deriv f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound #align convex.lipschitz_on_with_of_nnnorm_deriv_le Convex.lipschitzOnWith_of_nnnorm_deriv_le /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–deriv f xβ€–β‚Š ≀ C) : LipschitzWith C f := lipschitzOn_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x #align lipschitz_with_of_nnnorm_deriv_le lipschitzWith_of_nnnorm_deriv_le /-- If `f : π•œ β†’ G`, `π•œ = R` or `π•œ = β„‚`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π•œ f) (hf' : βˆ€ x, deriv f x = 0) (x y : π•œ) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ #align is_const_of_deriv_eq_zero is_const_of_deriv_eq_zero end Convex end /-! ### Functions `[a, b] β†’ ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ β†’ ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ β†’ ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : βˆƒ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x have hhh' : βˆ€ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a)) have hhc : ContinuousOn h (Icc a b) := (continuousOn_const.mul hfc).sub (continuousOn_const.mul hgc) rcases exists_hasDerivAt_eq_zero hab hhc hI hhh' with ⟨c, cmem, hc⟩ exact ⟨c, cmem, sub_eq_zero.1 hc⟩ #align exists_ratio_has_deriv_at_eq_ratio_slope exists_ratio_hasDerivAt_eq_ratio_slope /-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[>] a) (𝓝 <| (lgb - lga) * lfa - (lfb - lfa) * lga) := (tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga) convert this using 2 ring have hhb : Tendsto h (𝓝[<] b) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[<] b) (𝓝 <| (lgb - lga) * lfb - (lfb - lfa) * lgb) := (tendsto_const_nhds.mul hfb).sub (tendsto_const_nhds.mul hgb) convert this using 2 ring
let h' x := (lgb - lga) * f' x - (lfb - lfa) * g' x
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[>] a) (𝓝 <| (lgb - lga) * lfa - (lfb - lfa) * lga) := (tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga) convert this using 2 ring have hhb : Tendsto h (𝓝[<] b) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[<] b) (𝓝 <| (lgb - lga) * lfb - (lfb - lfa) * lgb) := (tendsto_const_nhds.mul hfb).sub (tendsto_const_nhds.mul hgb) convert this using 2 ring
Mathlib.Analysis.Calculus.MeanValue.742_0.ReDurB0qNQAwk9I
/-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : βˆƒ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c
Mathlib_Analysis_Calculus_MeanValue